I had a helpful answer for that:

> ansible server -m setup -i production, should provide you the correct
info.
> I suspect one of your hosts does not have an ipv4 address assigned to
eth1.


I added a condition:

{% if hostvars[host]['ansible_eth1']['active'] %}

(replace eth1 by eth0 in your case)

see
https://groups.google.com/forum/#!msg/ansible-project/RS1Mvdfjk2k/plfaT1g7cN0J


hope this helps

Le 03/12/2014 18:04, Gordon Ross a écrit :
> 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

-- 
Jean-Philippe Caruana 
http://www.barreverte.fr

-- 
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/547F4930.8040105%40target2sell.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to