template lookup: fix regression when templating hostvars (#64070)
This fixes a regression that was caused by switching from copy() to deepcopy() when 'saving' variables before templating. Since HostVars did not implement the __deepcopy__() method, deepcopy returned incorrect results when host vars were present in the variables. Fixes #63940
This commit is contained in:
parent
22fe622589
commit
cd8ce16d48
6 changed files with 22 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- template lookup - fix regression when templating hostvars (https://github.com/ansible/ansible/issues/63940)
|
|
@ -111,6 +111,12 @@ class HostVars(Mapping):
|
|||
out[host] = self.get(host)
|
||||
return repr(out)
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
# We do not need to deepcopy because HostVars is immutable,
|
||||
# however we have to implement the method so we can deepcopy
|
||||
# variables' dicts that contain HostVars.
|
||||
return self
|
||||
|
||||
|
||||
class HostVarsVars(Mapping):
|
||||
|
||||
|
|
|
@ -11,3 +11,5 @@ pip install passlib
|
|||
ANSIBLE_ROLES_PATH=../ ansible-playbook lookups.yml "$@"
|
||||
|
||||
ansible-playbook template_lookup_vaulted.yml --vault-password-file test_vault_pass "$@"
|
||||
|
||||
ansible-playbook -i template_deepcopy/hosts template_deepcopy/playbook.yml "$@"
|
||||
|
|
1
test/integration/targets/lookups/template_deepcopy/hosts
Normal file
1
test/integration/targets/lookups/template_deepcopy/hosts
Normal file
|
@ -0,0 +1 @@
|
|||
h1 ansible_connection=local host_var=foo
|
|
@ -0,0 +1,10 @@
|
|||
- hosts: h1
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- set_fact:
|
||||
templated_foo: "{{ lookup('template', 'template.in') }}"
|
||||
|
||||
- name: Test that the hostvar was templated correctly
|
||||
assert:
|
||||
that:
|
||||
- templated_foo == "foo\n"
|
|
@ -0,0 +1 @@
|
|||
{{hostvars['h1'].host_var}}
|
Loading…
Reference in a new issue