From 8eb7d740b02571fdbfc3fae1f1aa99192882da27 Mon Sep 17 00:00:00 2001 From: Michel Blanc Date: Thu, 24 Jan 2013 00:53:12 +0100 Subject: [PATCH] Fixes hash merging No need for deep copy (vars are essentially immutable once loaded, there should not be any modifications) --- lib/ansible/utils/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index 5bf5cf7a2a2..139e1584e9c 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -280,21 +280,19 @@ def merge_hash(a, b): which value comes from b said differently, all key/value combination from b will override a's ''' - # let's create a deep copy of a - result = copy.deepcopy(a) # and iterate over b keys for k, v in b.iteritems(): - if k in result and isinstance(result[k], dict): + if k in a and isinstance(a[k], dict): # if this key is a hash and exists in a # we recursively call ourselves with # the key value of b - result[k] = merge_hash(result[k], v) + a[k] = merge_hash(a[k], v) else: # k is not in a, no need to merge b, we just deecopy # or k is not a dictionnary, no need to merge b either, we just deecopy it - result[k] = copy.deepcopy(v) + a[k] = v # finally, return the resulting hash when we're done iterating keys - return result + return a def md5s(data): ''' Return MD5 hex digest of data. '''