title: Ansible - Using a "when" conditional statement on a loop to exclude matching interfaces
body: <p>I currently have a functional playbook that reaches out to network devices, returns the LLDP output, formats it then writes it back to the device's interfaces. We've run into an issue where we need to exclude specific interfaces (which are specified in host_vars) so as to not be overwritten. The issue I'm running into is at this point in the playbook:</p>
  <pre><code>- name: CONFIGURE PORT DESCRIPTIONS USING NEIGHBOR DATA
      include_tasks: lldp_int_desc.yml
      with_items: &quot;{{ neighbors.response }}&quot;
      when: &quot;{{ item.local_interface }} not in {{ excluded_ports }}&quot;
  </code></pre>
  <p>I was originally trying to use &quot;block&quot; and &quot;when&quot; statements however I quickly learned they do not work with loops so the workaround is to use include_tasks. The conditional &quot;when&quot; statement is taking the local interface from the returned LLDP output and checking that against the list of interfaces in the host_vars directory:</p>
  <pre><code>---
  excluded_ports:
   - Eth1/10
   - Eth1/11
  </code></pre>
  <p>The error is:</p>
  <p><strong>&quot;The conditional check '{{ item.local_interface }} not in {{ excluded_ports }}' failed. The error was: template error while templating string: expected token ',', got 'string'. String: {% if Eth1/5 not in [u'Eth1/10', u'Eth1/11'] %} True {% else %} False {% endif %}</strong></p>
  <p>So it appears to be an issue with the first variable being a string while the second is a list? I'm not sure how else to display the excluded_ports info. I've thought about creating specific when statements per-interface but that seems to defeat the purpose of a loop. Any help is greatly appreciated.</p>