# ansible\_default\_ipv4 not getting populated

**URL:** <https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057>\
**Category:** Ansible Project\
**Tags:** kubernetes, ubuntu\
**Created:** [November 19, 2016, 4:22pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057 "2016-11-19T16:22:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikram\_Ranabhatt](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vikram\_Ranabhatt](https://forum.ansible.com/u/Vikram_Ranabhatt)\
**Post date:** [November 19, 2016, 4:22pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/1 "2016-11-19T16:22:07Z")

</div>

I setting up kubernetes cluster with 3 master and 5 node.I am deploying through ansible.

I am able to create these node.

I am using ansible 2.2.0.0. on host machine from where I am launching my script.

ansible\_default\_ipv4 is not getting populated and ansible script is failing while executing the following line.

```auto
{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{ item }}

```

I have feeling that this could be because of environmental issue.  
Please help me figure out this issue.

I am using

```auto
Linux installterinceptionvm2 4.2.0-30-generic #36~14.04.1-Ubuntu SMP Fri Feb 26 18:49:23 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

```

---

<div class="post-metadata">

**Author:** ![Ali\_Jabir](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Ali\_Jabir](https://forum.ansible.com/u/Ali_Jabir)\
**Post date:** [November 19, 2016, 5:15pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/2 "2016-11-19T17:15:25Z")

</div>

What error does the playbook throw?

---

<div class="post-metadata">

**Author:** ![Vikram\_Ranabhatt](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vikram\_Ranabhatt](https://forum.ansible.com/u/Vikram_Ranabhatt)\
**Post date:** [November 19, 2016, 5:50pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/3 "2016-11-19T17:50:06Z")

</div>

TASK [common : Hosts | populate inventory into hosts file] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [inception-vm]: FAILED! =\> {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘dict object’ has no attribute ‘ansible\_default\_ipv4’\n\nThe error appears to have been in ‘/home/ubuntu/ansible/roles/common/tasks/main.yml’: line 52, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Hosts | populate inventory into hosts file\n ^ here\n”}

**ansible -m setup -i inventory/inventory all -a “filter=_ipv4_”**

---

<div class="post-metadata">

**Author:** ![Ali\_Jabir](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Ali\_Jabir](https://forum.ansible.com/u/Ali_Jabir)\
**Post date:** [November 19, 2016, 6:09pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/4 "2016-11-19T18:09:39Z")

</div>

Vikram,

I believe ansible\_default\_ipv4 is not fetched by ansible in the first go. Try removing the facts of the respective host and running again. Make sure you are gathering the facts first.

-AliJ

---

<div class="post-metadata">

**Author:** ![Vikram\_Ranabhatt](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vikram\_Ranabhatt](https://forum.ansible.com/u/Vikram_Ranabhatt)\
**Post date:** [November 19, 2016, 6:55pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/5 "2016-11-19T18:55:45Z")

</div>

> HI Ali,

I added gather\_facts: yes but no luck

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 19, 2016, 7:18pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/6 "2016-11-19T19:18:32Z")

</div>

> ---  
> -hosts:all  
> &nbsp;&nbsp;gather\_facts:yes  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;-name:vikram  
> # debug: msg="vikram"  
> &nbsp;&nbsp;&nbsp;&nbsp;#debug: msg={{ hostvars[item] }}  
> &nbsp;&nbsp;&nbsp;&nbsp;debug:msg={{hostvars[item]['ansible\_default\_ipv4']['address']}}  
> &nbsp;&nbsp;&nbsp;&nbsp;with\_items:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-"{{ groups['all'] }}"
> 
> \*Output:\*  
> TASK  
> [setup]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal:[openam-instance]:UNREACHABLE!=\>{"changed":false,"msg":"Failed to  
> connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[kuberenetes-node-2]:UNREACHABLE!=\>{"changed":false,"msg":"Failed  
> to connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[kuberenetes-node-3]:UNREACHABLE!=\>{"changed":false,"msg":"Failed  
> to connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[kuberenetes-node-4]:UNREACHABLE!=\>{"changed":false,"msg":"Failed  
> to connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[kuberenetes-node-5]:UNREACHABLE!=\>{"changed":false,"msg":"Failed  
> to connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[kuberenetes-master-2]:UNREACHABLE!=\>{"changed":false,"msg":"Failed to  
> connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[kuberenetes-master-3]:UNREACHABLE!=\>{"changed":false,"msg":"Failed to  
> connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[edge-instance-1]:UNREACHABLE!=\>{"changed":false,"msg":"Failed to  
> connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[kuberenetes-master-1]:UNREACHABLE!=\>{"changed":false,"msg":"Failed to  
> connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[kuberenetes-node-1]:UNREACHABLE!=\>{"changed":false,"msg":"Failed  
> to connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> ok:[inception]  
> fatal:[edge-instance-2]:UNREACHABLE!=\>{"changed":false,"msg":"Failed to  
> connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}  
> fatal:[opendj-instance]:UNREACHABLE!=\>{"changed":false,"msg":"Failed to  
> connect to the host via ssh: Connection timed out during banner  
> exchange\r\n","unreachable":true}

This is the fact gathering step, as you can see from the output, only 1 of 13 hosts are reachable

> TASK  
> [vikram]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal:[inception]:FAILED!=\>{"failed":true,"msg":"the field 'args' has an  
> invalid value, which appears to include a variable that is undefined.  
> The error was: 'dict object' has no attribute  
> 'ansible\_default\_ipv4'\n\nThe error appears to have been in  
> '/home/ubuntu/ansible/test1.yml': line 7, column 5, but may\nbe  
> elsewhere in the file depending on the exact syntax problem.\n\nThe  
> offending line appears to be:\n\n\n - name: vikram\n ^ here\n"}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to retry,use:--limit @/home/ubuntu/ansible/test1.retry

Since you have 12 unreachable host your loop will have 12 undefined variables.

In the first iteration  
hostvars[item]['ansible\_default\_ipv4']['address']  
will be  
hostvars['openam-instance']['ansible\_default\_ipv4']['address']

Since host openam-instance is unreachable this is a undefined variable.  
To make it not fail you need to filter it through the default filter.

debug: msg={{ hostvars[item]['ansible\_default\_ipv4']['address'] | deffault() }}

---

<div class="post-metadata">

**Author:** ![Vikram\_Ranabhatt](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vikram\_Ranabhatt](https://forum.ansible.com/u/Vikram_Ranabhatt)\
**Post date:** [November 19, 2016, 8:16pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/7 "2016-11-19T20:16:24Z")

</div>

Thanks kai for your suggestion.  
but actual purpose of  
hostvars[item][‘ansible\_default\_ipv4’][‘address’]  
Is to add entry in hosts file in each machine.  
Do you have any idea why this ansible\_default\_ipv4 is not available??

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 19, 2016, 8:30pm UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/8 "2016-11-19T20:30:04Z")

</div>

I tried to explain that in my previous mail, I'm not sure if I can explain it more clearly than I did.  
Maybe someone else can explain it better.

I can try one more go.

You have 13 hosts, but you are only able to reach 1 of them.  
You need to fix that so you can log in to all 13 and not just the one host called "inception".  
The other 12 hosts you get a UNREACHABLE! if you look at you output, solve them at it will work.

Since 12 of 13 hosts are UNREACHABLE you are not able to log in and collect the facts about them and thats why ansible\_default\_ipv4 is not available.

---

<div class="post-metadata">

**Author:** ![Ali\_Jabir](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Ali\_Jabir](https://forum.ansible.com/u/Ali_Jabir)\
**Post date:** [November 20, 2016, 1:45am UTC](https://forum.ansible.com/t/ansible-default-ipv4-not-getting-populated/23057/9 "2016-11-20T01:45:44Z")

</div>

Hi Vikram,

Kai is right, now that you have shared your code. You are trying to display default\_ipv4\_address of all the hosts. Since the hosts are unreachable, Ansible is unable to gather facts, hence it cannot find default\_ipv4\_address of all the hosts and verily cannot display them. Try to resolve the connectivity issue first.

Thanks  
-AliJ
