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
Conversation
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 ansible#63940
# however we have to implement the method so we can deepcopy | ||
# variables' dicts that contain HostVars. | ||
return self | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just missing a changelog, but looks good otherwise.
test/integration/targets/lookups/template_deepcopy/playbook.yml
Outdated
Show resolved
Hide resolved
- name: Test that the hostvar was templated correctly | ||
assert: | ||
that: | ||
- templated_foo == "foo\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- templated_foo == "foo\n" | |
- templated_foo == "{{ host_var }}\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the gain? In tests I don't really care about duplicate code. I prefer to use the actual values for comparisons. That way it does not depend on the templating engine (like {{hostvars['h1'].host_var}}
might equal to {{ host_var }}
but if it is templated to an incorrect value we won't find out because the comparison would still be true, however it's unlikely).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given it's the actual templating engine that's being tested I guess hard coded values makes sense. I would have switched to the variable just because folks looking to write their first tests often look for simple examples and assume the simple example is the way it should always be done.
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 ansible#63940 (cherry picked from commit cd8ce16)
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 (cherry picked from commit cd8ce16)
SUMMARY
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 incorrectresults when host vars were present in the variables.
Fixes #63940
ISSUE TYPE
COMPONENT NAME
template lookup