# AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible\_all\_ipv4\_addresses'"

**URL:** <https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541>\
**Category:** Ansible Project\
**Created:** [January 29, 2021, 3:46pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541 "2021-01-29T15:46:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aris\_Aguirre](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Aris\_Aguirre](https://forum.ansible.com/u/Aris_Aguirre)\
**Post date:** [January 29, 2021, 3:46pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541/1 "2021-01-29T15:46:42Z")

</div>

Below is working when I was still using ansible 2.3 or maybe 2.7 But no longer ansible 2.8 or 2.9. Please be advise no matter what it is not working.  
Thanks

{% for host in groups.all %}  
{{ hostvars[host][‘ansible\_all\_ipv4\_addresses’][0] }} {{ hostvars[host][‘ansible\_fqdn’] }} {{ hostvars[host][‘inventory\_hostname\_short’] }}  
{% endfor %}

Below is the actual error.

FAILED! =\> {“changed”: false, “msg”: “AnsibleUndefinedVariable: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘ansible\_all\_ipv4\_addresses’”}

---

<div class="post-metadata">

**Author:** ![Mauricio\_Tavares](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mauricio\_Tavares](https://forum.ansible.com/u/Mauricio_Tavares)\
**Post date:** [January 29, 2021, 8:33pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541/2 "2021-01-29T20:33:54Z")

</div>

> Below is working when I was still using ansible 2.3 or maybe 2.7 But no longer ansible 2.8 or 2.9. Please be advise no matter what it is not working.  
> Thanks
> 
> {% for host in groups.all %}  
> {{ hostvars[host]['ansible\_all\_ipv4\_addresses'][0] }} {{ hostvars[host]['ansible\_fqdn'] }} {{ hostvars[host]['inventory\_hostname\_short'] }}  
> {% endfor %}
> 
> Below is the actual error.
> 
> FAILED! =\> {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible\_all\_ipv4\_addresses'"}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Something else might be funky there:

raub@desktop:~/dev/ansible$ ansible dns2 -m setup |grep -i ipv4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ansible\_all\_ipv4\_addresses": [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ansible\_default\_ipv4": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"tx\_checksum\_ipv4": "off [fixed]",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ipv4": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"tx\_checksum\_ipv4": "off [fixed]",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ipv4": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"tx\_checksum\_ipv4": "off [fixed]",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ipv4": {  
raub@desktop:~/dev/ansible$ ansible --version  
ansible 2.9.17  
&nbsp;&nbsp;config file = /home/raub/dev/ansible/ansible.cfg  
&nbsp;&nbsp;configured module search path =  
[u'/home/raub/.ansible/plugins/modules',  
u'/usr/share/ansible/plugins/modules']  
&nbsp;&nbsp;ansible python module location = /usr/lib/python2.7/dist-packages/ansible  
&nbsp;&nbsp;executable location = /usr/bin/ansible  
&nbsp;&nbsp;python version = 2.7.12 (default, Oct 5 2020, 13:56:01) [GCC 5.4.0 20160609]  
raub@desktop:~/dev/ansible$

---

<div class="post-metadata">

**Author:** ![Aris\_Aguirre](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Aris\_Aguirre](https://forum.ansible.com/u/Aris_Aguirre)\
**Post date:** [January 29, 2021, 10:18pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541/3 "2021-01-29T22:18:15Z")

</div>

NO funky… it is just not working if it is being user in FOR LOOP. As ive said…its working fine in Jinja template or 2.3 2.7. But its not workin in the for loop like before.

ansible dev -m setup |grep -i ipv4  
“ansible\_all\_ipv4\_addresses”: [  
“ansible\_default\_ipv4”: {  
“tx\_checksum\_ipv4”: “off [fixed]”,  
“ipv4”: {  
“tx\_checksum\_ipv4”: “off [fixed]”,  
“tx\_checksum\_ipv4”: “off [fixed]”,  
“ipv4”: {

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [January 29, 2021, 11:27pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541/4 "2021-01-29T23:27:00Z")

</div>

I just solved this for me today. I’m away from work so I can’t copy my code. I created ip0, ip1 and ip2 in vars, set gather facts and did a set facts using a when is defined.

Mike

---

<div class="post-metadata">

**Author:** ![Aris\_Aguirre](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Aris\_Aguirre](https://forum.ansible.com/u/Aris_Aguirre)\
**Post date:** [January 30, 2021, 3:13pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541/5 "2021-01-30T15:13:07Z")

</div>

DO you mind showing me, Is this a new problem?

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [January 30, 2021, 3:37pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541/6 "2021-01-30T15:37:27Z")

</div>

I don’t mind at all. 🙂

---

<div class="post-metadata">

**Author:** ![Aris\_Aguirre](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Aris\_Aguirre](https://forum.ansible.com/u/Aris_Aguirre)\
**Post date:** [February 1, 2021, 1:23pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541/7 "2021-02-01T13:23:03Z")

</div>

Got it, Ill just call the {{ ip0 }} in Jinja. Hope there’s other way to figure it out using the for LOOP.

Thank you

---

<div class="post-metadata">

**Author:** ![Aris\_Aguirre](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Aris\_Aguirre](https://forum.ansible.com/u/Aris_Aguirre)\
**Post date:** [February 1, 2021, 1:42pm UTC](https://forum.ansible.com/t/ansibleundefinedvariable-ansible-vars-hostvars-hostvarsvars-object-has-no-attribute-ansible-all-ipv4-addresses/34541/8 "2021-02-01T13:42:10Z")

</div>

well i did not define anything now, it is working as my original. I just use hosts: all instead of hosts: db.
