AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_all_ipv4_addresses'"

179 views
Skip to first unread message

Aris Aguirre

unread,
Jan 29, 2021, 10:46:43 AM1/29/21
to Ansible Project
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'"}

Mauricio Tavares

unread,
Jan 29, 2021, 3:34:17 PM1/29/21
to ansible...@googlegroups.com
Something else might be funky there:

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

> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0bc08e12-07aa-4df5-854c-4bcba9324605n%40googlegroups.com.

Aris Aguirre

unread,
Jan 29, 2021, 5:18:15 PM1/29/21
to Ansible Project
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": {

Mike Eggleston

unread,
Jan 29, 2021, 6:28:09 PM1/29/21
to ansible...@googlegroups.com
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

On Jan 29, 2021, at 16:18, Aris Aguirre <aris...@gmail.com> wrote:



Aris Aguirre

unread,
Jan 30, 2021, 10:13:07 AM1/30/21
to Ansible Project
DO you mind showing me, Is this a new problem?

Mike Eggleston

unread,
Jan 30, 2021, 10:37:42 AM1/30/21
to ansible...@googlegroups.com
I don’t mind at all. :)

- hosts: all
  gather_facts: yes

  vars:
    ip0: “”
    ip1: “”
    ip2: “”

  tasks:
    - set_fact:
        ip0: “{{ansible_all_ipv4_addressess[0]}}”
      when: ansible_all_ipv4_addresses[0] is defined

And the same for 1 and 2.

Mike

Aris Aguirre

unread,
Feb 1, 2021, 8:23:03 AM2/1/21
to Ansible Project


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

Aris Aguirre

unread,
Feb 1, 2021, 8:42:34 AM2/1/21
to ansible...@googlegroups.com
well i did not define anything now, it is working as my original. I just use hosts: all  instead of hosts: db.

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/QtciviR_CBg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/59FCD0D4-959D-4E82-BE70-BA0C8BC30998%40gmail.com.
Reply all
Reply to author
Forward
0 new messages