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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- template lookup - fix regression when templating hostvars (https://github.com/ansible/ansible/issues/63940) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
h1 ansible_connection=local host_var=foo |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{hostvars['h1'].host_var}} |
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()
onHostVars
returns self and sodeepcopy()
does not continue further down the structure to be applied onHostVarsVars
.