Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template lookup: fix regression when templating hostvars #64070

Merged
merged 3 commits into from Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ansible/vars/hostvars.py
Expand Up @@ -111,6 +111,12 @@ def __repr__(self):
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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need same in hostvarsvars

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is needed because deepcopy() on HostVars returns self and so deepcopy() does not continue further down the structure to be applied on HostVarsVars.


class HostVarsVars(Mapping):

Expand Down
2 changes: 2 additions & 0 deletions test/integration/targets/lookups/runme.sh
Expand Up @@ -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 change: 1 addition & 0 deletions test/integration/targets/lookups/template_deepcopy/hosts
@@ -0,0 +1 @@
h1 ansible_connection=local host_var=foo
@@ -0,0 +1,5 @@
- hosts: h1
gather_facts: no
tasks:
- debug:
msg: "{{ lookup('template', 'template.in') }}"
mkrizek marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1 @@
{{hostvars['h1'].host_var}}