diff --git a/changelogs/fragments/add-ansible_index_var-to-tasks_vars.yaml b/changelogs/fragments/add-ansible_index_var-to-tasks_vars.yaml new file mode 100644 index 0000000000..c23f0c9372 --- /dev/null +++ b/changelogs/fragments/add-ansible_index_var-to-tasks_vars.yaml @@ -0,0 +1,2 @@ +minor_changes: + - Make ``ansible_index_var`` accessible as a magic variable. diff --git a/docs/docsite/rst/reference_appendices/special_variables.rst b/docs/docsite/rst/reference_appendices/special_variables.rst index 920a37f8a7..f46ce6b030 100644 --- a/docs/docsite/rst/reference_appendices/special_variables.rst +++ b/docs/docsite/rst/reference_appendices/special_variables.rst @@ -31,6 +31,9 @@ ansible_loop ansible_loop_var The name of the value provided to ``loop_control.loop_var``. Added in ``2.8`` +ansible_index_var + The name of the value provided to ``loop_control.index_var``. Added in ``2.9`` + ansible_parent_role_names When the current role is being executed by means of an :ref:`include_role ` or :ref:`import_role ` action, this variable contains a list of all parent roles, with the most recent role (i.e. the role that included/imported this role) being the first item in the list. When multiple inclusions occur, this list lists the *last* role (i.e. the role that included this role) as the *first* item in the list. It is also possible that a specific role exists more than once in this list. diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 0865a3a50b..7b65df1031 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -324,6 +324,7 @@ class TaskExecutor: task_vars[loop_var] = item if index_var: + task_vars['ansible_index_var'] = index_var task_vars[index_var] = item_index if extended: