According to the Ansible docs ( http://docs.ansible.com/faq.html#how-do-i-loop-over-a-list-of-hosts-in-a-group-inside-of-a-template ) You can put the following in a template:
{% for host in groups[’test_servers'] %}
{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}
{% endfor %}
But when I do that, I get:
TASK: [Template Test] *********************************************************
fatal: [srv.exmpale.com] => {'msg': "One or more undefined variables: 'dict object' has no attribute 'ansible_eth0'", 'failed': True}
If I put:
{% for host in groups['test_servers'] %}
{{ hostvars[host] }}
{% endfor %}
then I get a Python formatted output of all the facts.
Yet if I put in the template:
{{ hostvars[inventory_hostname]['ansible_eth0']['ipv4']['address'] }}
or
{{ hostvars['srv.exmpale.com']['ansible_eth0']['ipv4']['address'] }}
Then that works and I get the IP address in the file.
Google only reveals someone who had the same problem and gave up
Thanks,
GTG