diff options
author | Steve Milner <smilner@redhat.com> | 2017-01-13 12:12:38 -0500 |
---|---|---|
committer | Steve Milner <smilner@redhat.com> | 2017-01-13 12:12:38 -0500 |
commit | 998cddda23c0fa2402eb904a2585d1390703fb08 (patch) | |
tree | dbf2de8cb610463b8b861fecf821f958768f44f3 | |
parent | 78b948edb0c30e3ec876916a8bbe08db5f055ea7 (diff) | |
download | openshift-998cddda23c0fa2402eb904a2585d1390703fb08.tar.gz openshift-998cddda23c0fa2402eb904a2585d1390703fb08.tar.bz2 openshift-998cddda23c0fa2402eb904a2585d1390703fb08.tar.xz openshift-998cddda23c0fa2402eb904a2585d1390703fb08.zip |
Updated modify_yaml with docstring and clarifications
-rwxr-xr-x | library/modify_yaml.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/library/modify_yaml.py b/library/modify_yaml.py index d8d22d5ea..8706e80c2 100755 --- a/library/modify_yaml.py +++ b/library/modify_yaml.py @@ -6,6 +6,11 @@ import yaml +# ignore pylint errors related to the module_utils import +# pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import +from ansible.module_utils.basic import * # noqa: F402,F403 + + DOCUMENTATION = ''' --- module: modify_yaml @@ -21,8 +26,18 @@ EXAMPLES = ''' ''' -# pylint: disable=missing-docstring def set_key(yaml_data, yaml_key, yaml_value): + ''' Updates a parsed yaml structure setting a key to a value. + + :param yaml_data: yaml structure to modify. + :type yaml_data: dict + :param yaml_key: Key to modify. + :type yaml_key: mixed + :param yaml_value: Value use for yaml_key. + :type yaml_value: mixed + :returns: Changes to the yaml_data structure + :rtype: dict(tuple()) + ''' changes = [] ptr = yaml_data final_key = yaml_key.split('.')[-1] @@ -75,6 +90,7 @@ def main(): # pylint: disable=missing-docstring, unused-argument def none_representer(dumper, data): return yaml.ScalarNode(tag=u'tag:yaml.org,2002:null', value=u'') + yaml.add_representer(type(None), none_representer) try: @@ -95,14 +111,9 @@ def main(): # ignore broad-except error to avoid stack trace to ansible user # pylint: disable=broad-except - except Exception as e: - return module.fail_json(msg=str(e)) - + except Exception as error: + return module.fail_json(msg=str(error)) -# ignore pylint errors related to the module_utils import -# pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import, wrong-import-position -# import module snippets -from ansible.module_utils.basic import * # noqa: F402,F403 if __name__ == '__main__': main() |