I’ve run into a deprecation error related to an undefined variable in a with_items loop. The task definition is below:
name: template syslog config snippets
template:
src: “{{ item }}.conf.j2”
dest: “/etc/rsyslog.d/{{ item }}.conf”
mode: 0644
with_items: “{{ syslog.snippets|default(1) }}”
when: syslog is defined
notify:
- restart rsyslog
The “when” clause was originally ‘when: syslog is defined and syslog.snippets is defined’, but I was getting the deprecation warning for both syslog and syslog.snippets and I found various threads which explained the issue with when clauses and loops, so I adjusted it as suggested. However, because the list I’m referencing is actually a value of a dict key, I still need to test that ‘syslog’ is defined, but I’m still getting the deprecation warning about ‘syslog’ not being defined.
[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error.: ‘syslog’ is undefined.
This
feature will be removed in a future release.
Is there a way to test for this effectively, or is my only option to define a ‘fake’ syslog var for servers that don’t have it, so that it passes the test for syslog, but not syslog.snippets?
Thanks,
Guy