Well, after reading the other discussion, I think you are right. The safest
is to use the default. The conditional can be unpredictable which was what
I was afraid and why I started this thread.
Ansible should avoid these situations. Or maybe provide a warning of
potential unsafe situations.

About the plugins, I dont think it is possible to use those in AWX.

Thank you for your input.

Regards,

Nuno Jordão

On Tue, Feb 18, 2020 at 7:22 PM Vladimir Botka <[email protected]> wrote:

> On Tue, 18 Feb 2020 14:45:34 +0000
> Nuno Jordão <[email protected]> wrote:
>
> > Some times I dont like to use the loop: "{{ nulo|default([]) }}" because
> it
> > doesn't say "skipping" and in complex playbook with lots of hosts I like
> to
> > have that feedback.
>
> You might want to find a plugin which fits your needs
> https://docs.ansible.com/ansible/latest/plugins/callback.html#plugin-list
>
> > ... I think that, probably, the behaviour changed, and
> > the documentation should be more clear in this regard... The conditional
> is
> > not applied only per item but also to the task...
> >
> > [...]
> >     - name: "test loop"
> >       debug:
> >         msg: "test"
> >       loop: "{{nulo}}"
> >       when: nulo is defined
>
> You're right. "when" is also applied before the loop starts. Let me point
> to
> 2 more cases which describe the complexity. The task below
>
>    - debug:
>         msg: "test"
>       loop: "{{ nulo }}"
>       when:
>         - nulo is defined
>         - item is search('PATTERN')
>
> is skipped because "when" stops evaluating a conjunction after the first
> element fails
>
>    skipping: [localhost]
>
>
> But when the order of the conditions is changed the task
>
>     - debug:
>         msg: "test"
>       loop: "{{ nulo }}"
>       when:
>         - item is search('PATTERN')
>         - nulo is defined
>
> fails because the evaluation of "item" leads to the evaluation of "nulo"
>
>     fatal: [localhost]: FAILED! => {"msg": "'nulo' is undefined"}
>
>
> As a result, I argue that "{{ nulo|default([]) }}" should be preferred in
> term of "keep it simple stupid".
> https://en.wikipedia.org/wiki/KISS_principle
>
> It's been also discussed here
> https://groups.google.com/forum/#!topic/ansible-project/Y1mGC3vrsng
>
> HTH,
>
>         -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/CAEAA%3DtuCnGjS6QVUQTCV1nFHCRC6BqChm%3D5BhAPWBV3FWxKOGg%40mail.gmail.com.

Reply via email to