From b8d057296a4096047f0d6fe07e032e13f6879996 Mon Sep 17 00:00:00 2001 From: Serge van Ginderachter Date: Thu, 21 Aug 2014 17:40:47 +0200 Subject: [PATCH] variable merging: detect if both vars are really dicts when combining/merging dicts --- lib/ansible/utils/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index c18174b00d2..401d35ed860 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -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: