Hello,
Thank you for your responses.
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.
I tested several options and and everything works, even the case of the issue 45976 (should have tested that one before). 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…
vars:
tstbool: False
tstnull:
tasks:
-
name: “test loop”
debug:
msg: “test”
loop: “{{nulo|default()}}”
-
name: “test loop”
debug:
msg: “test”
loop: “{{nulo}}”
when: nulo is defined
-
name: “test loop”
debug:
msg: “test”
loop: “{{nulo}}”
when: nulo|default(False)
-
name: “test loop”
debug:
msg: “test”
loop: “{{nulo}}”
when: nulo|default()|length > 0
-
name: “test loop”
debug:
msg: “test”
loop: “{{nulo}}”
when: tstbool
-
name: “test loop”
debug:
msg: “test”
loop: “{{nulo}}”
when: tstnull
Returns:
PLAY [localhost] *****************************************************************************************************
TASK [test loop] *****************************************************************************************************
TASK [test loop] *****************************************************************************************************
skipping: [localhost]
TASK [test loop] *****************************************************************************************************
skipping: [localhost]
TASK [test loop] *****************************************************************************************************
skipping: [localhost]
TASK [test loop] *****************************************************************************************************
skipping: [localhost]
TASK [test loop] *****************************************************************************************************[DEPRECATION WARNING]: evaluating None as a bare variable, this behaviour will go away and you might need to add
bool to the expression in the future. Also see CONDITIONAL_BARE_VARS configuration toggle… This feature will be
removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
skipping: [localhost]
PLAY RECAP ***********************************************************************************************************localhost : ok=0 changed=0 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0
The final count for skipped is 6 but the first task doesn’t report skipping