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

pull/8710/head
Serge van Ginderachter 10 years ago
parent 8a1fbed5d6
commit b8d057296a

@ -696,10 +696,17 @@ def parse_kv(args):
options[k.strip()] = unquote(v.strip()) options[k.strip()] = unquote(v.strip())
return options 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): def merge_hash(a, b):
''' recursively merges hash b into a ''' recursively merges hash b into a
keys from b take precedence over keys from a ''' keys from b take precedence over keys from a '''
_validate_both_dicts(a, b)
result = {} result = {}
for dicts in a, b: for dicts in a, b:
@ -1308,6 +1315,8 @@ def listify_lookup_plugin_terms(terms, basedir, inject):
def combine_vars(a, b): def combine_vars(a, b):
_validate_both_dicts(a, b)
if C.DEFAULT_HASH_BEHAVIOUR == "merge": if C.DEFAULT_HASH_BEHAVIOUR == "merge":
return merge_hash(a, b) return merge_hash(a, b)
else: else:

Loading…
Cancel
Save