Undefined variables when using hostvars.iteritems()

Folks, The following code is producing errors.

code:

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

error:

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

192.168.111.222 hostnameA
192.168.111.211 hostnameB
...

Thanks!

Looks like you figured it out in the other thread.