variable merging: detect if both vars are really dicts when combining/merging dicts

This commit is contained in:
Serge van Ginderachter 2014-08-21 17:40:47 +02:00
parent 8a1fbed5d6
commit b8d057296a

View file

@ -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: