mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
Add support for defining index var for task loops
This commit is contained in:
parent
7be8079bad
commit
e9b0a4ccb4
6 changed files with 58 additions and 1 deletions
3
test/integration/targets/loops/tasks/index_var_tasks.yml
Normal file
3
test/integration/targets/loops/tasks/index_var_tasks.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
- name: check that index var exists inside included tasks file
|
||||
assert:
|
||||
that: my_idx == item|int
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue