`when` statements are not evaluated before the task starts. They are evaluated for each iteration of the loop. So by the time it is evaluated, ansible is already trying to loop the undefined variable.
In 1.9 this was silently ignored, and the task was skipped.
In 2.0 we added the deprecation notice.
The correct way is to ensure that `with_items` gets an iterable variable. We recommend the use of the `|default` filter.
The problem becomes more difficult if the variable is multiple layers, such as `syslog.snippets`, so there are a few ways to do this:
with_items: "{{ (syslog|default(dict()))['snippets']|default([]) }}"
Or potentially with using 'combine', such as:
with_items: "{{ (syslog|combine(dict(snippets=[])))['snippets'] }}"
Both are a little complicated.
Other options are to always define this in a way that allows the task to not have complicated loop data. Maybe even specifying it as a group_vars or similar.
Or perhaps to use an `set_fact` task to do some of the heavy lifting before you try to use it.
One last option, use less complex variables.