ansible - when statements should not include jinja2 templating delimiters : <p>I'm hoping someone could help. I was wondering what is the correct syntax in using the <code>when</code> statement? I have this playbook:</p>

<pre><code>- set_fact:
   sh_vlan_id: "{{ output.response|map(attribute='vlan_id')|list|join(',') }}"

- name: create vlans
  ios_config:
    provider: "{{ provider }}"
    parents: vlan {{ item.id }}
    lines: name {{ item.name }}
    with_items: "{{ vlans }}"
  register: result
  when: '"{{ item.id }}" not in sh_vlan_id'
</code></pre>

<p>and during run it gives me a warning but it actually accept it. I not sure if this is ok or not.</p>

<pre><code>TASK [set_fact]    *************************************************************************************************************************
ok: [acc_sw_01]

TASK [create vlans] *********************************************************************************************************************
[WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: "{{ item.id }}" not in sh_vlan_id

skipping: [acc_sw_01] =&gt; (item={u'id': 10, u'name': u'voice-1'}) 
skipping: [acc_sw_01] =&gt; (item={u'id': 101, u'name': u'data-2'}) 
skipping: [acc_sw_01] =&gt; (item={u'id': 100, u'name': u'data-1'}) 
changed: [acc_sw_01] =&gt; (item={u'id': 11, u'name': u'voice-2'})
</code></pre>

<p>But if I remove the curly braces in <code>item.id</code> in <code>when</code> statement </p>

<pre><code>when: item.id not in sh_vlan_id
</code></pre>

<p>It gives me an error:</p>

<pre><code>TASK [set_fact] *************************************************************************************************************************
ok: [acc_sw_01]

TASK [create vlans] *********************************************************************************************************************
fatal: [acc_sw_01]: FAILED! =&gt; {"failed": true, "msg": "The conditional check 'item.id not in sh_vlan_id' failed. The error was: Unexpected templating type error occurred on ({% if item.id not in sh_vlan_id %} True {% else %} False {% endif %}): coercing to Unicode: need string or buffer, int found\n\nThe error appears to have been in '/ansible/cisco-ansible/config_tasks/vlan.yml': line 16, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: create vlans\n  ^ here\n"}
</code></pre>

<p>I'm using ansible 2.3.0 (devel cbedc4a12a) btw. Thanks</p>
