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

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’”}

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'"}

      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$

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

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

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

I don’t mind at all. :slight_smile:

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

Thank you

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