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 00000000000..abcae68494d --- /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 577792eb965..d48d64c83e9 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: