Browse Source

Merge pull request #7243 from mgugino-upstream-stage/filter-dict-check

Cast string to dict in lib_utils_oo_dict_to_keqv_list
Michael Gugino 7 years ago
parent
commit
fef8df420e
1 changed files with 10 additions and 0 deletions
  1. 10 0
      roles/lib_utils/filter_plugins/oo_filters.py

+ 10 - 0
roles/lib_utils/filter_plugins/oo_filters.py

@@ -4,6 +4,7 @@
 """
 Custom filters for use in openshift-ansible
 """
+import ast
 import json
 import os
 import pdb
@@ -248,6 +249,15 @@ def lib_utils_oo_dict_to_keqv_list(data):
         Return data:
         ['a=1', 'b=2']
     """
+    if not isinstance(data, dict):
+        try:
+            # This will attempt to convert something that looks like a string
+            # representation of a dictionary (including json) into a dictionary.
+            data = ast.literal_eval(data)
+        except ValueError:
+            msg = "|failed expects first param is a dict. Got {}. Type: {}"
+            msg = msg.format(str(data), str(type(data)))
+            raise errors.AnsibleFilterError(msg)
     return ['='.join(str(e) for e in x) for x in data.items()]