On Fri, 8 Nov 2019 06:13:10 -0800 (PST) "'Tobias Kirchhofer' via Ansible Project" <[email protected]> wrote:
> >
> > Use *default* and *skip_missing* subelements. For example
> >
> > loop: "{{ FIREWALLD_ZONE_SERVICE|default([])|
> > subelements('SERVICES', skip_missing=True) }}"
>
> Thank you! This is working. Is only needed with 'subelements'. But why?
I guess
- *subelements* filter is executed before *when*, because
- *when* is evaluated on each iteration, because
- *when* argument can change on each iteration (e.g. may include *item*).
- *when* can not be evaluated before *subelements*, because *item* does not
exist yet.
The loop will fail
loop: "{{ FIREWALLD_ZONE_SERVICE|subelements('SERVICES') }}"
when: FIREWALLD_ZONE_SERVICE is defined
FAILED! => {"msg": "'FIREWALLD_ZONE_SERVICE' is undefined"}
The loop below is skipped when FIREWALLD_ZONE_SERVICE is not defined
(this is not consistent, it should also fail. Source would reveal why)
loop: "{{ FIREWALLD_ZONE_SERVICE }}"
when: FIREWALLD_ZONE_SERVICE is defined
,but it will also fail if the evaluation of the *loop* argument
(FIREWALLD_ZONE_SERVICE) before *when* is forced e.g.
loop: "{{ FIREWALLD_ZONE_SERVICE }}"
when: item|length > 10 and
FIREWALLD_ZONE_SERVICE is defined
FAILED! => {"msg": "'FIREWALLD_ZONE_SERVICE' is undefined"}
Cheers,
-vlado
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/20191108165559.594a8593%40gmail.com.
pgpBkMXH0WY3B.pgp
Description: OpenPGP digital signature
