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

Conversation

mkrizek
Copy link
Contributor

@mkrizek mkrizek commented Oct 29, 2019

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 incorrect
results when host vars were present in the variables.

Fixes #63940

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

template lookup

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
@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. has_issue needs_triage Needs a first human triage before being processed. small_patch support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 29, 2019
# 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.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Oct 29, 2019
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Oct 31, 2019
Copy link
Member

@sivel sivel left a 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.

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Nov 5, 2019
@tremble tremble mentioned this pull request Nov 5, 2019
- name: Test that the hostvar was templated correctly
assert:
that:
- templated_foo == "foo\n"
Copy link
Contributor

@tremble tremble Nov 5, 2019

Choose a reason for hiding this comment

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

Suggested change
- templated_foo == "foo\n"
- templated_foo == "{{ host_var }}\n"

Copy link
Contributor Author

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).

Copy link
Contributor

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.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Nov 5, 2019
@mkrizek mkrizek merged commit cd8ce16 into ansible:devel Nov 6, 2019
@mkrizek mkrizek deleted the issue-63940 branch November 6, 2019 14:25
mkrizek added a commit to mkrizek/ansible that referenced this pull request Nov 6, 2019
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)
mattclay pushed a commit that referenced this pull request Nov 12, 2019
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)
@ansible ansible locked and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. has_issue support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

template lookup plugin regression 2.8.6 -> 2.9.0rc5, if expansion contains hostvars references
6 participants