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
TaskExecutor: update_vars (add magic vars) before post_validate #22156
Conversation
* Fixes ansible#21639 - a failure of "'varname' is undefined" resulting from redefining a magic var with a value that includes another magic var. * Avoids the error by restoring the sequence of `update_vars()` executing before `post_validate()`, as existed prior to 479cbfc.
self._play_context.post_validate(templar=templar) | ||
|
||
# now that the play context is finalized, if the remote_addr is not set | ||
# default to using the host's address field as the remote address |
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.
we cannot set remote_addr w/o post_validating first
|
||
# now that the play context is finalized, if the remote_addr is not set | ||
# default to using the host's address field as the remote address | ||
# if the remote_addr is not set, default to using the host's address field | ||
if not self._play_context.remote_addr: | ||
self._play_context.remote_addr = self._host.address | ||
|
||
# We also add "magic" variables back into the variables dict to make sure | ||
# a certain subset of variables exist. | ||
self._play_context.update_vars(variables) |
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.
some of the magic vars rely on post_validate already being run to have the correct value
alternate fix #38861 |
Closing since this was resolved by #38861. |
ISSUE TYPE
COMPONENT NAME
TaskExecutor
ANSIBLE VERSION
SUMMARY
Fixes #21639
Concept. Magic vars are not available for consumption (are undefined) in the explicit redefinition of other magic vars.
Example. Suppose a user's definition of
ansible_become_pass
includesansible_user
. Despite passing the--user
CLI option, the definition below will produce'ansible_user' is undefined
.Proposed solution. This PR avoids the error by restoring the sequence of
update_vars()
executing beforepost_validate()
, as existed prior to 479cbfc. This in unfamiliar code for me, so a team member familiar with TaskExecutor may want to review/confirm this revised execution sequence.Aside: It appears good to keep the
remote_addr
update before theupdate_vars()
so that the latter can add theansible_ssh_host
andansible_host
magic vars.Steps to reproduce
Test playbook:
Test command:
Output from current devel:
Output after PR: