diff --git a/changelogs/fragments/49474-network_utils_dict_merge_fix.yaml b/changelogs/fragments/49474-network_utils_dict_merge_fix.yaml new file mode 100644 index 00000000000..c8baf54e129 --- /dev/null +++ b/changelogs/fragments/49474-network_utils_dict_merge_fix.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- fixes an issue with dict_merge in network utils (https://github.com/ansible/ansible/pull/49474) diff --git a/lib/ansible/module_utils/network/common/utils.py b/lib/ansible/module_utils/network/common/utils.py index 1e281bbb151..260b8558f4a 100644 --- a/lib/ansible/module_utils/network/common/utils.py +++ b/lib/ansible/module_utils/network/common/utils.py @@ -34,6 +34,7 @@ from itertools import chain from struct import pack 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.moves import zip from ansible.module_utils.basic import AnsibleFallbackNotFound @@ -275,7 +276,10 @@ def dict_merge(base, other): if key in other: item = other.get(key) if item is not None: - combined[key] = dict_merge(value, other[key]) + if isinstance(other[key], Mapping): + combined[key] = dict_merge(value, other[key]) + else: + combined[key] = other[key] else: combined[key] = item else: