summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Butcher <abutcher@afrolegs.com>2017-01-16 10:33:16 -0500
committerGitHub <noreply@github.com>2017-01-16 10:33:16 -0500
commit62918051b0526d9e86f8f569ceba8574a18b61ec (patch)
tree396a6df05a7e992197a11d107500cf29b0a89e1d
parent2bd657a6a20f960a3bbdf01cc84472ff5b94fa1a (diff)
parent998cddda23c0fa2402eb904a2585d1390703fb08 (diff)
downloadopenshift-62918051b0526d9e86f8f569ceba8574a18b61ec.tar.gz
openshift-62918051b0526d9e86f8f569ceba8574a18b61ec.tar.bz2
openshift-62918051b0526d9e86f8f569ceba8574a18b61ec.tar.xz
openshift-62918051b0526d9e86f8f569ceba8574a18b61ec.zip
Merge pull request #3091 from ashcrow/modify-yaml
Updated modify_yaml with docstring and clarifications
-rwxr-xr-xlibrary/modify_yaml.py27
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()