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
-- 
Gordon Ross

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/29B50496-ECB1-49CA-91B0-28DF61E925BF%40uis.cam.ac.uk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to