title: Adding to yaml list using a loop
body: <p>I am using the geerlingguy.firewall ansible galaxy role to add iptables rules. In that there is a firewall_additional_rules list variable where I am adding in some scripts to allow from certain ips, which I want to provide with a another list variable</p>
  
  <pre><code>white_listed_ips:
     - 1.1.1.1
     - 1.1.1.2
  </code></pre>
  
  <p>etc</p>
  
  <p>I want to be able to generate the firewall_additional_rules list from the white_listed_ips list, by looping through. However I can't find any way of doing this. Can you loop through variables and add to an array in yaml?</p>
  
  <p>So I want to do something like this in a var file (I know this doesn't work, indulge me)</p>
  
  <pre><code>firewall_additional_rules:
  {% for ip in white_listed_ips %}
    - iptables -A INPUT -p tcp -s {{ ip }} --dport ssh -j ACCEPT
    - iptables -A INPUT -p tcp -s {{ ip }} --dport 80 -j ACCEPT
  {% endfor %}
  </code></pre>
  
  <p>This is to go into the jinja2 template in the role, you can see here:
  <a href="https://github.com/geerlingguy/ansible-role-firewall/blob/master/templates/firewall.bash.j2" rel="nofollow">https://github.com/geerlingguy/ansible-role-firewall/blob/master/templates/firewall.bash.j2</a></p>