mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07:00
[k8s] allow user to pass list of resources in to definition parameter (#42377)
* allow user to pass list of resources in to definition parameter * Add new validator for list|dict|string * use string_types instead of string * state/force information is lost after the first item in the list * Add tests * Appease ansibot
This commit is contained in:
parent
dfb2b3fdd5
commit
e9c7b513a1
4 changed files with 125 additions and 5 deletions
|
@ -22,8 +22,8 @@ import os
|
|||
import copy
|
||||
|
||||
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
|
||||
try:
|
||||
import kubernetes
|
||||
|
@ -51,6 +51,16 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def list_dict_str(value):
|
||||
if isinstance(value, list):
|
||||
return value
|
||||
elif isinstance(value, dict):
|
||||
return value
|
||||
elif isinstance(value, string_types):
|
||||
return value
|
||||
raise TypeError
|
||||
|
||||
ARG_ATTRIBUTES_BLACKLIST = ('property_path',)
|
||||
|
||||
COMMON_ARG_SPEC = {
|
||||
|
@ -63,6 +73,7 @@ COMMON_ARG_SPEC = {
|
|||
'default': False,
|
||||
},
|
||||
'resource_definition': {
|
||||
'type': list_dict_str,
|
||||
'aliases': ['definition', 'inline']
|
||||
},
|
||||
'src': {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.k8s.common import KubernetesAnsibleModule
|
||||
|
||||
|
||||
|
@ -50,11 +51,13 @@ class KubernetesRawModule(KubernetesAnsibleModule):
|
|||
namespace = self.params.pop('namespace')
|
||||
resource_definition = self.params.pop('resource_definition')
|
||||
if resource_definition:
|
||||
if isinstance(resource_definition, str):
|
||||
if isinstance(resource_definition, string_types):
|
||||
try:
|
||||
self.resource_definitions = yaml.safe_load_all(resource_definition)
|
||||
except (IOError, yaml.YAMLError) as exc:
|
||||
self.fail(msg="Error loading resource_definition: {0}".format(exc))
|
||||
elif isinstance(resource_definition, list):
|
||||
self.resource_definitions = resource_definition
|
||||
else:
|
||||
self.resource_definitions = [resource_definition]
|
||||
src = self.params.pop('src')
|
||||
|
@ -100,8 +103,8 @@ class KubernetesRawModule(KubernetesAnsibleModule):
|
|||
|
||||
def perform_action(self, resource, definition):
|
||||
result = {'changed': False, 'result': {}}
|
||||
state = self.params.pop('state', None)
|
||||
force = self.params.pop('force', False)
|
||||
state = self.params.get('state', None)
|
||||
force = self.params.get('force', False)
|
||||
name = definition.get('metadata', {}).get('name')
|
||||
namespace = definition.get('metadata', {}).get('namespace')
|
||||
existing = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue