Add support for defining index var for task loops

This commit is contained in:
Andrew Gaffney 2018-01-26 14:29:04 -07:00 committed by Brian Coca
commit e9b0a4ccb4
6 changed files with 58 additions and 1 deletions

View file

@ -0,0 +1,3 @@
- name: check that index var exists inside included tasks file
assert:
that: my_idx == item|int

View file

@ -1,3 +1,7 @@
#
# loop_control/pause
#
- name: Measure time before
shell: date +%s
register: before
@ -146,3 +150,29 @@
that:
- 'results10["results"][0]["ping"] == "Hello World"'
- 'results10["results"][1]["ping"] == "Olá Mundo"'
#
# loop_control/index_var
#
- name: check that the index var is created and increments as expected
assert:
that: my_idx == item|int
with_sequence: start=0 count=3
loop_control:
index_var: my_idx
- name: check that value of index var matches position of current item in source list
assert:
that: 'test_var.index(item) == my_idx'
vars:
test_var: ['a', 'b', 'c']
with_items: "{{ test_var }}"
loop_control:
index_var: my_idx
- name: check index var with included tasks file
include_tasks: index_var_tasks.yml
with_sequence: start=0 count=3
loop_control:
index_var: my_idx