summaryrefslogtreecommitdiff
path: root/lib/ansible/vars
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2018-06-26 15:10:04 -0500
committerGitHub <noreply@github.com>2018-06-26 15:10:04 -0500
commit1401fa74cc39b44ea6ddd1d4b5c5eac9fb82bbf9 (patch)
treef0cb1342afbe2a8897027bbc5c7ed1991b33b111 /lib/ansible/vars
parent11ce9542269daa9e388d0d1995bd891a1a55d4a0 (diff)
downloadansible-1401fa74cc39b44ea6ddd1d4b5c5eac9fb82bbf9.tar.gz
Cache items when task.loop/with_items is evaluated to set delegate_to vars (#41969)
* If we evaluate task.loop/with_items when calculating delegate_to vars, cache the items. Fixes #28231 * Add comments about caching loop items * Add test for delegate_to+loop+random * Be more careful about where we update task.loop
Diffstat (limited to 'lib/ansible/vars')
-rw-r--r--lib/ansible/vars/manager.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py
index 923c10dafd..6f104b518d 100644
--- a/lib/ansible/vars/manager.py
+++ b/lib/ansible/vars/manager.py
@@ -498,10 +498,19 @@ class VariableManager:
# This task will be skipped later due to this, so we just setup
# a dummy array for the later code so it doesn't fail
items = [None]
+ # Update task.loop with templated items, this ensures that delegate_to+loop
+ # doesn't produce different restuls than TaskExecutor which may reprocess the loop
+ # Set loop_with to None, so we don't do extra unexpected processing on the cached items later
+ # in TaskExecutor
+ task.loop_with = None
+ task.loop = items
else:
raise AnsibleError("Failed to find the lookup named '%s' in the available lookup plugins" % task.loop_with)
elif task.loop is not None:
items = templar.template(task.loop)
+ # Update task.loop with templated items, this ensures that delegate_to+loop
+ # doesn't produce different restuls than TaskExecutor which may reprocess the loop
+ task.loop = items
else:
items = [None]