-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Don't use the task for a cache, return a special cache var #47243
Conversation
if loop_cache is not None: | ||
# _ansible_loop_cache may be set in `get_vars` when calculating `delegate_to` | ||
# to avoid reprocessing the loop | ||
items = copy.copy(loop_cache) |
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.
wouldn't we need a deepcopy here?
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.
Oh, actually, I can remove that all together. I had added it when I was removing it from _job_vars
.
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.
Removed
Hi @sivel, thank you for submitting this pull-request! |
…ar (ansible#47243) * Don't use task to cache loop results, use hostvars. Fixes ansible#47207 * Avoid a race condition, supply _ansible_loop_cache through get_vars directly * Add tests * Add changelog fragment * Remove unnecessary copy * Remove unnecessary host from _get_delegated_vars signature. (cherry picked from commit 77d32b8) Co-authored-by: Matt Martz <matt@sivel.net>
…ar (#47243) * Don't use task to cache loop results, use hostvars. Fixes #47207 * Avoid a race condition, supply _ansible_loop_cache through get_vars directly * Add tests * Add changelog fragment * Remove unnecessary copy * Remove unnecessary host from _get_delegated_vars signature. (cherry picked from commit 77d32b8) Co-authored-by: Matt Martz <matt@sivel.net>
…7243) * Don't use task to cache loop results, use hostvars. Fixes ansible#47207 * Avoid a race condition, supply _ansible_loop_cache through get_vars directly * Add tests * Add changelog fragment * Remove unnecessary copy * Remove unnecessary host from _get_delegated_vars signature
SUMMARY
This PR addresses an issue where looping over a hostvar, with a templated
delegate_to
would create a loop cache on the task for the last host in the loop. Fixes #47207The original problem that was being solved was the following:
Because we process the loop in
VariableManager._get_delegated_vars
and inTaskExecutor._get_loop_items
that loop could produce different results, causingansible_delegated_vars
to not exist for the host later selected inTaskExecutor._get_loop_items
We solved that by caching the resultant loop as
task.loop
. The problem with that is when the variable being looped is different per host.This fix allows the original case to work, as well as the case of:
ISSUE TYPE
COMPONENT NAME
lib/ansible/executor/task_executor.py
lib/ansible/vars/manager.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
Also, not mentioned above is that an inventory was supplied to some other tests that were skipping as a result of the inventory not matching.