The documentation shows this as the prefered method: `with_items:
"{{undefined_var| default([]) }}"`.
An empty list for the loop will skip the task, no need for `when`.

http://docs.ansible.com/ansible/playbooks_conditionals.html#loops-and-conditionals

A strategy that does as you describe will have several issues, many `when`​
conditions will issue undefined errors as they expect the loop variable
(normally `item`) or some other variable that derives it's value directly
or indirectly from it. Since it can also be renamed via `loop_control`
searching for `item` is not feasible.

This pattern was always an error, it 'worked' in 1.9 because a bug in
ansible 'ignored' the exception, 2.0 stopped doing that and made it a fatal
error. Since many users had this issue we changed it to a deprecation
warning and scheduled it for removal in 2.2. Since this is a 'definition'
error we are remiss to just 'skip' those as we cannot be sure that the
`when` clause is meant to catch them or not. The conditinoals are also
dynamic and not resolved until inside the loop, which is also the reason we
cannot 'special case' defined/undefined conditionals, since they can be
written many different ways.


----------
Brian Coca

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7c1j0%3DesQAorQH7kPRDvY%3D_%3DtAScofc4SR%3D2QQNgCbcyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to