ansible - when statements should not include jinja2 templating delimiters
The "correct" syntax is to not include jinja templates as indicated by the warning. Your condition doesn't work otherwise because the types are not compatible.
You could try type coercion:
when: ' item.id|string not in sh_vlan_id'
See: http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters
Another example for reference ..
- name: Sudoers | update sudoers file and validate
lineinfile: "dest=/etc/sudoers
insertafter=EOF
line='{{ item.username }} ALL=(ALL) NOPASSWD: ALL'
regexp='^{{ item.username }} .*'
state=present"
when: '{{ item.use_sudo }} == True'
with_items: '{{users}}'
I was getting below orning.
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: "{{ item.use_sudo}}" == True
After making the below changes into the playbook it works fine.
- name: Sudoers | update sudoers file and validate
lineinfile: "dest=/etc/sudoers
insertafter=EOF
line='{{ item.username }} ALL=(ALL) NOPASSWD: ALL'
regexp='^{{ item.username }} .*'
state=present"
when: 'item.use_sudo|bool'
with_items: '{{users}}'
UPD: if you use variable type boolean
that == True
not need