mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Add info about loop based on jinja2 loop var (#42134)
* Add info about loop based on jinja2 loop var * ansible_loop * Update test count * Add extended loop_control that defines whether ansible_loop should be added * Extended needs to be defaulted * Revert "Update test count" This reverts commit f1e93ee469825f4cdcd90fb28667d29aa088275c. * Add docs about loop_control.extended * Add revindex and revindex0 * Document ansible_loop in special vars * Add changelog fragment * Add tests, change items to allitems so that dot notation works, fix logic error with previtem
This commit is contained in:
parent
597c258e0e
commit
9007dbec2f
6 changed files with 117 additions and 0 deletions
|
@ -268,3 +268,66 @@
|
|||
things:
|
||||
- !unsafe foo
|
||||
- !unsafe bar
|
||||
|
||||
- name: extended loop info
|
||||
assert:
|
||||
that:
|
||||
- ansible_loop.nextitem == 'orange'
|
||||
- ansible_loop.index == 1
|
||||
- ansible_loop.index0 == 0
|
||||
- ansible_loop.first
|
||||
- not ansible_loop.last
|
||||
- ansible_loop.previtem is undefined
|
||||
- ansible_loop.allitems == ['apple', 'orange', 'banana']
|
||||
- ansible_loop.revindex == 3
|
||||
- ansible_loop.revindex0 == 2
|
||||
- ansible_loop.length == 3
|
||||
loop:
|
||||
- apple
|
||||
- orange
|
||||
- banana
|
||||
loop_control:
|
||||
extended: true
|
||||
when: item == 'apple'
|
||||
|
||||
- name: extended loop info 2
|
||||
assert:
|
||||
that:
|
||||
- ansible_loop.nextitem == 'banana'
|
||||
- ansible_loop.index == 2
|
||||
- ansible_loop.index0 == 1
|
||||
- not ansible_loop.first
|
||||
- not ansible_loop.last
|
||||
- ansible_loop.previtem == 'apple'
|
||||
- ansible_loop.allitems == ['apple', 'orange', 'banana']
|
||||
- ansible_loop.revindex == 2
|
||||
- ansible_loop.revindex0 == 1
|
||||
- ansible_loop.length == 3
|
||||
loop:
|
||||
- apple
|
||||
- orange
|
||||
- banana
|
||||
loop_control:
|
||||
extended: true
|
||||
when: item == 'orange'
|
||||
|
||||
- name: extended loop info 3
|
||||
assert:
|
||||
that:
|
||||
- ansible_loop.nextitem is undefined
|
||||
- ansible_loop.index == 3
|
||||
- ansible_loop.index0 == 2
|
||||
- not ansible_loop.first
|
||||
- ansible_loop.last
|
||||
- ansible_loop.previtem == 'orange'
|
||||
- ansible_loop.allitems == ['apple', 'orange', 'banana']
|
||||
- ansible_loop.revindex == 1
|
||||
- ansible_loop.revindex0 == 0
|
||||
- ansible_loop.length == 3
|
||||
loop:
|
||||
- apple
|
||||
- orange
|
||||
- banana
|
||||
loop_control:
|
||||
extended: true
|
||||
when: item == 'banana'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue