title: ansible how to use a variable in a for loop
body: <p>I have an ansible task like this:</p>
  
  <pre><code>- name: coreos network configuration
      {% for interface in argument['interfaces'] %}
        {% if argument[interface]['role'] == 'ingest' %}
    script: netconfiginput.sh -i {{interface}} #incorrect, how to get the value of the interface variable of the for loop?
        {% endif %}
      {% endfor %}
  </code></pre>
  
  <p>While running this ansible task, I pass a JSON string argument:</p>
  
  <pre><code>ansible-playbook --extra-vars 'argument={"interfaces":["eno1","eno2","ep8s0"],"eno2":{"role":"ingest"}}' network-config.yml
  </code></pre>
  
  <p>What I want to do is, loop through the JSON array called <code>interfaces</code>, which are a list of network interfaces, when the <code>role</code> of the interface is called <code>ingest</code>, I run a script and pass the network interface as an argument to the script, my implementation is incorrect, how can I do this?   </p>