Thank you for the b <https://groups.google.com/forum/#!msg/ansible-project/Y1mGC3vrsng/8DZRiJU6AwAJ>ackground explanation! Interesting.
Am Freitag, 8. November 2019 16:56:11 UTC+1 schrieb Vladimir Botka: > > On Fri, 8 Nov 2019 06:13:10 -0800 (PST) > "'Tobias Kirchhofer' via Ansible Project" <[email protected] > <javascript:>> > 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/aa993808-0cf9-4651-9fac-960a00cecd39%40googlegroups.com.
