variable merging: detect if both vars are really dicts when combining/merging dicts
This commit is contained in:
parent
8a1fbed5d6
commit
b8d057296a
1 changed files with 9 additions and 0 deletions
|
@ -696,10 +696,17 @@ def parse_kv(args):
|
|||
options[k.strip()] = unquote(v.strip())
|
||||
return options
|
||||
|
||||
def _validate_both_dicts(a, b):
|
||||
|
||||
if not (isinstance(a, dict) and isinstance(b, dict)):
|
||||
raise errors.AnsibleError("Failed to combine two values which are not "
|
||||
"both hashes, got these differing values now:\n\n%s\n and\n%s" % (a, b))
|
||||
|
||||
def merge_hash(a, b):
|
||||
''' recursively merges hash b into a
|
||||
keys from b take precedence over keys from a '''
|
||||
|
||||
_validate_both_dicts(a, b)
|
||||
result = {}
|
||||
|
||||
for dicts in a, b:
|
||||
|
@ -1308,6 +1315,8 @@ def listify_lookup_plugin_terms(terms, basedir, inject):
|
|||
|
||||
def combine_vars(a, b):
|
||||
|
||||
_validate_both_dicts(a, b)
|
||||
|
||||
if C.DEFAULT_HASH_BEHAVIOUR == "merge":
|
||||
return merge_hash(a, b)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue