mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
Add optional 'skip_missing' flag to subelements
This commit is contained in:
parent
1ca8cb8553
commit
9b646dea41
4 changed files with 157 additions and 17 deletions
|
@ -39,7 +39,7 @@
|
|||
set_fact: "{{ item.0 + item.1 }}=x"
|
||||
with_nested:
|
||||
- [ 'a', 'b' ]
|
||||
- [ 'c', 'd' ]
|
||||
- [ 'c', 'd' ]
|
||||
|
||||
- debug: var=ac
|
||||
- debug: var=ad
|
||||
|
@ -97,6 +97,39 @@
|
|||
- "_ye == 'e'"
|
||||
- "_yf == 'f'"
|
||||
|
||||
- name: test with_subelements in subkeys
|
||||
set_fact: "{{ '_'+ item.0.id + item.1 }}={{ item.1 }}"
|
||||
with_subelements:
|
||||
- element_data
|
||||
- the.sub.key.list
|
||||
|
||||
- name: verify with_subelements in subkeys results
|
||||
assert:
|
||||
that:
|
||||
- "_xq == 'q'"
|
||||
- "_xr == 'r'"
|
||||
- "_yi == 'i'"
|
||||
- "_yo == 'o'"
|
||||
|
||||
- name: test with_subelements with missing key or subkey
|
||||
set_fact: "{{ '_'+ item.0.id + item.1 }}={{ item.1 }}"
|
||||
with_subelements:
|
||||
- element_data_missing
|
||||
- the.sub.key.list
|
||||
- skip_missing: yes
|
||||
register: _subelements_missing_subkeys
|
||||
|
||||
- debug: var=_subelements_missing_subkeys.skipped
|
||||
- debug: var=_subelements_missing_subkeys.results|length
|
||||
- name: verify with_subelements in subkeys results
|
||||
assert:
|
||||
that:
|
||||
- _subelements_missing_subkeys.skipped is not defined
|
||||
- _subelements_missing_subkeys.results|length == 2
|
||||
- "_xk == 'k'"
|
||||
- "_xl == 'l'"
|
||||
|
||||
|
||||
# WITH_TOGETHER
|
||||
|
||||
- name: test with_together
|
||||
|
|
|
@ -3,7 +3,41 @@ element_data:
|
|||
the_list:
|
||||
- "f"
|
||||
- "d"
|
||||
the:
|
||||
sub:
|
||||
key:
|
||||
list:
|
||||
- "q"
|
||||
- "r"
|
||||
- id: y
|
||||
the_list:
|
||||
- "e"
|
||||
- "f"
|
||||
the:
|
||||
sub:
|
||||
key:
|
||||
list:
|
||||
- "i"
|
||||
- "o"
|
||||
element_data_missing:
|
||||
- id: x
|
||||
the_list:
|
||||
- "f"
|
||||
- "d"
|
||||
the:
|
||||
sub:
|
||||
key:
|
||||
list:
|
||||
- "k"
|
||||
- "l"
|
||||
- id: y
|
||||
the_list:
|
||||
- "f"
|
||||
- "d"
|
||||
- id: z
|
||||
the_list:
|
||||
- "e"
|
||||
- "f"
|
||||
the:
|
||||
sub:
|
||||
key:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue