title: Ansible loop through group vars in template
body: <p>I'm struggling with a pattern pulling inventory vars in Ansible templates, please help. :)</p>
  
  <p>I'm setting up a monitoring server, and I want to be able to automatically provision the servers using Ansible. I'm struggling with loops in the template to allow me to this.</p>
  
  <p>My semi-working soluition so far is in the playbook that calls the template task I have:</p>
  
  <p>monitoringserver.yml</p>
  
  <pre><code> vars:
         servers_to_monitor:
           - {cname: web1, ip_address: 192.168.33.111}
           - {cname: web2, ip_address: 192.168.33.112}
           - {cname: db1, ip_address: 192.168.33.211}
           - {cname: db2, ip_address: 192.168.33.212}
  </code></pre>
  
  <p>template.yml</p>
  
  <pre><code>all_hosts += [
             {% for host in servers_to_monitor %}
                     "{{ host.cname }}{{ host.ip }}|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
             {% endfor %}
  ] 
  </code></pre>
  
  <p>But this isn't ideal as I can't define different IP address for different servers to be monitoring. How have other people done this? I'm sure it must be trivial but my brain's struggling with the syntax.</p>
  
  <p>Thanks</p>
  
  <p>Alan</p>
  
  <p>edit: To clarify the resulting template looks something like this:</p>
  
  <pre><code>all_hosts += [
                          "web1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
                          "web2|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
                          "db1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
                          "db2|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
  ]
  </code></pre>
  
  <p>What I would like is the values web1/web2/db1/db2 to be different depending on whether I'm using a production inventory file or a development inventory file.</p>