From 5e03e322de5b43b69c8aad5c0cb92e82ce0f3d17 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Wed, 16 Dec 2020 11:23:23 -0500 Subject: [PATCH] Pass the top level dictionaries to combine_vars (#72979) * Pass the top level dictionaries to combine_vars combine_vars uses dict.update() to replace keys --- .../fragments/72979-fix-inventory-merge-hash-replace.yaml | 2 ++ lib/ansible/inventory/group.py | 2 +- lib/ansible/inventory/host.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/72979-fix-inventory-merge-hash-replace.yaml diff --git a/changelogs/fragments/72979-fix-inventory-merge-hash-replace.yaml b/changelogs/fragments/72979-fix-inventory-merge-hash-replace.yaml new file mode 100644 index 00000000000..4b7b24720af --- /dev/null +++ b/changelogs/fragments/72979-fix-inventory-merge-hash-replace.yaml @@ -0,0 +1,2 @@ +bugfixes: + - inventory - pass the vars dictionary to combine_vars instead of an individual key's value (https://github.com/ansible/ansible/issues/72975). diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py index d3efb1d8fa3..ed02fb4cca8 100644 --- a/lib/ansible/inventory/group.py +++ b/lib/ansible/inventory/group.py @@ -247,7 +247,7 @@ class Group: self.set_priority(int(value)) else: if key in self.vars and isinstance(self.vars[key], MutableMapping) and isinstance(value, Mapping): - self.vars[key] = combine_vars(self.vars[key], value) + self.vars = combine_vars(self.vars, {key: value}) else: self.vars[key] = value diff --git a/lib/ansible/inventory/host.py b/lib/ansible/inventory/host.py index 7ad300790d0..a3e41f53b65 100644 --- a/lib/ansible/inventory/host.py +++ b/lib/ansible/inventory/host.py @@ -143,7 +143,7 @@ class Host: def set_variable(self, key, value): if key in self.vars and isinstance(self.vars[key], MutableMapping) and isinstance(value, Mapping): - self.vars[key] = combine_vars(self.vars[key], value) + self.vars = combine_vars(self.vars, {key: value}) else: self.vars[key] = value