title: How to use when condition to loop in Ansible
body: <p>I need ansible to examine all the remote IP addresses, and if the remote system is in a particular subnet, then copy a file to the remote system. I'm having difficulty figuring out how to make ansible loop over a list or dictionary in the <code>when</code> clause.</p>
  
  <p>This throws a syntax error <code>Error was expected string or buffer</code>, because <code>ansible_all_ipv4_addresses</code> is a list or dictionary, not a string:</p>
  
  <pre><code>- name: auto.direct 10g
    copy: src=auto.direct.10g dest=/etc/auto.direct owner=root group=root mode=0644
    when: ansible_all_ipv4_addresses | search("192.168.17")
  </code></pre>