mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 15:11:23 -07:00
update module arguments to allow resource_definition to be a string (#40730)
This commit is contained in:
parent
5f5fbffe8a
commit
d75e49693b
4 changed files with 15 additions and 9 deletions
|
@ -63,7 +63,6 @@ COMMON_ARG_SPEC = {
|
||||||
'default': False,
|
'default': False,
|
||||||
},
|
},
|
||||||
'resource_definition': {
|
'resource_definition': {
|
||||||
'type': 'dict',
|
|
||||||
'aliases': ['definition', 'inline']
|
'aliases': ['definition', 'inline']
|
||||||
},
|
},
|
||||||
'src': {
|
'src': {
|
||||||
|
|
|
@ -23,9 +23,10 @@ from ansible.module_utils.k8s.common import KubernetesAnsibleModule
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import yaml
|
||||||
from openshift.dynamic.exceptions import DynamicApiError, NotFoundError, ConflictError
|
from openshift.dynamic.exceptions import DynamicApiError, NotFoundError, ConflictError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Exception handled in common
|
# Exceptions handled in common
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +50,13 @@ class KubernetesRawModule(KubernetesAnsibleModule):
|
||||||
namespace = self.params.pop('namespace')
|
namespace = self.params.pop('namespace')
|
||||||
resource_definition = self.params.pop('resource_definition')
|
resource_definition = self.params.pop('resource_definition')
|
||||||
if resource_definition:
|
if resource_definition:
|
||||||
self.resource_definitions = [resource_definition]
|
if isinstance(resource_definition, str):
|
||||||
|
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))
|
||||||
|
else:
|
||||||
|
self.resource_definitions = [resource_definition]
|
||||||
src = self.params.pop('src')
|
src = self.params.pop('src')
|
||||||
if src:
|
if src:
|
||||||
self.resource_definitions = self.load_resource_definitions(src)
|
self.resource_definitions = self.load_resource_definitions(src)
|
||||||
|
|
|
@ -99,12 +99,12 @@ EXAMPLES = '''
|
||||||
- name: Read definition file from the Ansible controller file system
|
- name: Read definition file from the Ansible controller file system
|
||||||
k8s:
|
k8s:
|
||||||
state: present
|
state: present
|
||||||
definition: "{{ lookup('file', '/testing/deployment.yml') | from_yaml }}"
|
definition: "{{ lookup('file', '/testing/deployment.yml') }}"
|
||||||
|
|
||||||
- name: Read definition file from the Ansible controller file system after Jinja templating
|
- name: Read definition file from the Ansible controller file system after Jinja templating
|
||||||
k8s:
|
k8s:
|
||||||
state: present
|
state: present
|
||||||
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
definition: "{{ lookup('template', '/testing/deployment.yml') }}"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -135,8 +135,8 @@ result:
|
||||||
returned: success
|
returned: success
|
||||||
type: complex
|
type: complex
|
||||||
items:
|
items:
|
||||||
description: Returned only when the I(kind) is a List type resource. Contains a set of objects.
|
description: Returned only when multiple yaml documents are passed to src or resource_definition
|
||||||
returned: when resource is a List
|
returned: when resource_definition or src contains list of objects
|
||||||
type: list
|
type: list
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,14 @@ class ModuleDocFragment(object):
|
||||||
options:
|
options:
|
||||||
resource_definition:
|
resource_definition:
|
||||||
description:
|
description:
|
||||||
- "Provide a valid YAML definition for an object when creating or updating. NOTE: I(kind), I(api_version), I(name),
|
- "Provide a valid YAML definition (either as a string or a dict) for an object when creating or updating. NOTE: I(kind), I(api_version), I(name),
|
||||||
and I(namespace) will be overwritten by corresponding values found in the provided I(resource_definition)."
|
and I(namespace) will be overwritten by corresponding values found in the provided I(resource_definition)."
|
||||||
aliases:
|
aliases:
|
||||||
- definition
|
- definition
|
||||||
- inline
|
- inline
|
||||||
src:
|
src:
|
||||||
description:
|
description:
|
||||||
- "Provide a path to a file containing a valid YAML definition of an object to be created or updated. Mutually
|
- "Provide a path to a file containing a valid YAML definition of an object or objects to be created or updated. Mutually
|
||||||
exclusive with I(resource_definition). NOTE: I(kind), I(api_version), I(name), and I(namespace) will be
|
exclusive with I(resource_definition). NOTE: I(kind), I(api_version), I(name), and I(namespace) will be
|
||||||
overwritten by corresponding values found in the configuration read in from the I(src) file."
|
overwritten by corresponding values found in the configuration read in from the I(src) file."
|
||||||
- Reads from the local file system. To read from the Ansible controller's file system, use the file lookup
|
- Reads from the local file system. To read from the Ansible controller's file system, use the file lookup
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue