mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-04 01:33:09 +00:00
variable merging: detect if both vars are really dicts when combining/merging dicts
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user