Allow for generating kubernetes YAML files from modules (#27833)

* Return the request dictionary in the results

It's sometimes useful to have access to the request params in a k8s
style. The dictionary returned by the request_params call can be
serialized into YAML to produce a k8s like file.

* Add dry_run option to skip module execution

By having support for dry_run executions, it'll be possible to generate
YAML files from the results dictionary by using the data in the
`requests` key.
pull/26323/head
Flavio Percoco Premoli 7 years ago committed by Chris Houseknecht
parent 3a86579b69
commit 4fad156768

@ -85,7 +85,17 @@ class KubernetesAnsibleModule(AnsibleModule):
:return: dict: a valid Ansible argument spec
"""
if not self.argspec_cache:
spec = {}
spec = {
'dry_run': {
'type': 'bool',
'default': False,
'description': [
"If set to C(True) the module will exit without executing any action."
"Useful to only generate YAML file definitions for the resources in the tasks."
]
}
}
for arg_name, arg_properties in self.helper.argspec.items():
spec[arg_name] = {}
for option, option_value in arg_properties.items():
@ -125,13 +135,19 @@ class KubernetesAnsibleModule(AnsibleModule):
state = self.params.get('state', None)
force = self.params.get('force', False)
dry_run = self.params.pop('dry_run', False)
name = self.params.get('name')
namespace = self.params.get('namespace', None)
existing = None
return_attributes = dict(changed=False, api_version=self.api_version)
return_attributes = dict(changed=False,
api_version=self.api_version,
request=self.helper.request_body_from_params(self.params))
return_attributes[self.helper.base_model_name_snake] = {}
if dry_run:
self.exit_json(**return_attributes)
try:
auth_options = {}
for key, value in self.helper.argspec.items():

Loading…
Cancel
Save