Skip to content
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

Make ansible_index_var accessible as a magic var #59030

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/add-ansible_index_var-to-tasks_vars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Make ``ansible_index_var`` accessible as a magic variable.
3 changes: 3 additions & 0 deletions docs/docsite/rst/reference_appendices/special_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <include_role_module>` or :ref:`import_role <import_role_module>` 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.
Expand Down
1 change: 1 addition & 0 deletions lib/ansible/executor/task_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def _run_loop(self, items):

task_vars[loop_var] = item
if index_var:
task_vars['ansible_index_var'] = index_var
task_vars[index_var] = item_index

if extended:
Expand Down