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/20200218202244.5a64dae9%40gmail.com.
pgptLLvuXP3Pf.pgp
Description: OpenPGP digital signature
