From 8e5956a98bfe5fda0345b2ea1e53d9a1050096c7 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Mon, 7 May 2018 18:09:48 -0500 Subject: [PATCH] Backport #39818 to stable-2.5 (#39824) * Update vars for loop_control on each loop iteration (fixes #38899) (#39818) (cherry picked from commit 01e8139d74916a0f87162944e28eede19af937d1) * Changelog snippet for cherry-pick of #39818 --- changelogs/fragments/39818-loop_control_task_vars.yaml | 2 ++ lib/ansible/executor/task_executor.py | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 changelogs/fragments/39818-loop_control_task_vars.yaml diff --git a/changelogs/fragments/39818-loop_control_task_vars.yaml b/changelogs/fragments/39818-loop_control_task_vars.yaml new file mode 100644 index 0000000000..abcae68494 --- /dev/null +++ b/changelogs/fragments/39818-loop_control_task_vars.yaml @@ -0,0 +1,2 @@ +bugfixes: + - loop_control - update template vars for loop_control fields on each loop iteration (https://github.com/ansible/ansible/pull/39818). diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 577792eb96..d48d64c83e 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -302,6 +302,9 @@ class TaskExecutor: if index_var: task_vars[index_var] = item_index + # Update template vars to reflect current loop iteration + templar.set_available_variables(task_vars) + # pause between loop iterations if loop_pause and ran_once: try: