summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorScott Dodson <sdodson@redhat.com>2016-08-08 17:19:38 -0400
committerGitHub <noreply@github.com>2016-08-08 17:19:38 -0400
commit2594364683976584c7654fee480a2ec5501dca59 (patch)
treedad8a33df9a39b33c965087494cbcad5e959d06b /library
parent9090df2d6c526d570d33d2315d90d80cc105750b (diff)
parentb3d04f1a54c0109ce38be103ddc7c83f1992c10e (diff)
downloadopenshift-2594364683976584c7654fee480a2ec5501dca59.tar.gz
openshift-2594364683976584c7654fee480a2ec5501dca59.tar.bz2
openshift-2594364683976584c7654fee480a2ec5501dca59.tar.xz
openshift-2594364683976584c7654fee480a2ec5501dca59.zip
Merge pull request #2211 from dgoodwin/33-upgrade-playbook
1.3 / 3.3 Upgrades
Diffstat (limited to 'library')
-rwxr-xr-xlibrary/modify_yaml.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/library/modify_yaml.py b/library/modify_yaml.py
index a4be10ca3..63b507a72 100755
--- a/library/modify_yaml.py
+++ b/library/modify_yaml.py
@@ -20,6 +20,24 @@ EXAMPLES = '''
yaml_value: 2
'''
+
+# pylint: disable=missing-docstring
+def set_key(yaml_data, yaml_key, yaml_value):
+ changes = []
+ ptr = yaml_data
+ for key in yaml_key.split('.'):
+ if key not in ptr and key != yaml_key.split('.')[-1]:
+ ptr[key] = {}
+ ptr = ptr[key]
+ elif key == yaml_key.split('.')[-1]:
+ if (key in ptr and module.safe_eval(ptr[key]) != yaml_value) or (key not in ptr):
+ ptr[key] = yaml_value
+ changes.append((yaml_key, yaml_value))
+ else:
+ ptr = ptr[key]
+ return changes
+
+
def main():
''' Modify key (supplied in jinja2 dot notation) in yaml file, setting
the key to the desired value.
@@ -53,22 +71,12 @@ def main():
yaml.add_representer(type(None), none_representer)
try:
- changes = []
yaml_file = open(dest)
yaml_data = yaml.safe_load(yaml_file.read())
yaml_file.close()
- ptr = yaml_data
- for key in yaml_key.split('.'):
- if key not in ptr and key != yaml_key.split('.')[-1]:
- ptr[key] = {}
- elif key == yaml_key.split('.')[-1]:
- if (key in ptr and module.safe_eval(ptr[key]) != yaml_value) or (key not in ptr):
- ptr[key] = yaml_value
- changes.append((yaml_key, yaml_value))
- else:
- ptr = ptr[key]
+ changes = set_key(yaml_data, yaml_key, yaml_value)
if len(changes) > 0:
if backup: