fixes an issue with dict_merge in network utils (#41107)

This change address a problem where the dict_merge function would fail
due to the value being a nested dict.  This will now recursively pass
the value back through the dict_merge function.
Merge to devel https://github.com/ansible/ansible/pull/41107

(cherry picked from commit 2a4be2748f)

Update changelog

Fix review comments
This commit is contained in:
Peter Sprygada 2018-11-30 07:22:33 -05:00 committed by Toshio Kuratomi
parent a928ea4d93
commit 799f8e97b3
2 changed files with 8 additions and 1 deletions

View file

@ -0,0 +1,3 @@
---
bugfixes:
- fixes an issue with dict_merge in network utils (https://github.com/ansible/ansible/pull/49474)

View file

@ -34,6 +34,7 @@ from itertools import chain
from struct import pack from struct import pack
from socket import inet_aton, inet_ntoa from socket import inet_aton, inet_ntoa
from ansible.module_utils.common._collections_compat import Mapping
from ansible.module_utils.six import iteritems, string_types from ansible.module_utils.six import iteritems, string_types
from ansible.module_utils.six.moves import zip from ansible.module_utils.six.moves import zip
from ansible.module_utils.basic import AnsibleFallbackNotFound from ansible.module_utils.basic import AnsibleFallbackNotFound
@ -275,7 +276,10 @@ def dict_merge(base, other):
if key in other: if key in other:
item = other.get(key) item = other.get(key)
if item is not None: if item is not None:
if isinstance(other[key], Mapping):
combined[key] = dict_merge(value, other[key]) combined[key] = dict_merge(value, other[key])
else:
combined[key] = other[key]
else: else:
combined[key] = item combined[key] = item
else: else: