Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Folks, The following code is producing errors.


{% for v in hostvars.iteritems() %}
    {{ v['ansible_all_ipv4_addresses'][0] }}  {{ v['ansible_hostname'] }}
{% endfor %}


{'msg': "One or more undefined variables: 'tuple object' has no attribute 'ansible_all_ipv4_addresses'", 'failed': True}

What should this look like if i wanted an /etc/hosts file like: hostnameA hostnameB


share|improve this question

1 Answer 1

up vote 1 down vote accepted

Looking at the Error message

'tuple object' has no attribute 'ansible_all_ipv4_addresses'

, it is clear that your hosts' facts does not either contain ansible_all_ipv4_addresses inside where you were searching or syntax parser caught you off-guard :)

Let's try this:

{% for minion in groups['web'] %}
 {{ hostvars[minion]['ansible_all_ipv4_addresses'][0] }} {{ hostvars[minion]['ansible_hostname'] }}
{% endfor %}

Consider we lay out our inventory like this

[web] hostnameA hostnameB

Hope it solves your problem. Cheers !!

share|improve this answer
The issue is hostvars.iteritems()... switching to groups solved my problems. – CMag Dec 11 '13 at 15:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.