# Undefined variables when using hostvars.iteritems()

**URL:** <https://forum.ansible.com/t/undefined-variables-when-using-hostvars-iteritems/14115>\
**Category:** Ansible Project\
**Created:** [December 10, 2013, 4:54pm UTC](https://forum.ansible.com/t/undefined-variables-when-using-hostvars-iteritems/14115 "2013-12-10T16:54:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vasiliy\_Boulytchev](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@Vasiliy\_Boulytchev](https://forum.ansible.com/u/Vasiliy_Boulytchev)\
**Post date:** [December 10, 2013, 4:54pm UTC](https://forum.ansible.com/t/undefined-variables-when-using-hostvars-iteritems/14115/1 "2013-12-10T16:54:28Z")

</div>

Folks, The following code is producing errors.

code:

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

```

error:

```auto
{'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:

```auto
192.168.111.222 hostnameA
192.168.111.211 hostnameB
...

```

Thanks!

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [December 10, 2013, 5:39pm UTC](https://forum.ansible.com/t/undefined-variables-when-using-hostvars-iteritems/14115/2 "2013-12-10T17:39:20Z")

</div>

Looks like you figured it out in the other thread.
