ansible_default_ipv4 not getting populated

4,221 views
Skip to first unread message

Vikram Ranabhatt

unread,
Nov 19, 2016, 11:22:07 AM11/19/16
to Ansible Project

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.


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

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

Ali Jabir

unread,
Nov 19, 2016, 12:16:17 PM11/19/16
to ansible...@googlegroups.com
What error does the playbook throw?

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/53b77512-6787-40e9-b9a6-ef5a0c33e36c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vikram Ranabhatt

unread,
Nov 19, 2016, 12:50:07 PM11/19/16
to Ansible Project
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"

third-party-instance | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Connection timed out during banner exchange\r\n",
    "unreachable": true
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
opendj | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Connection timed out during banner exchange\r\n",
    "unreachable": true
}
inception | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "10.32.1.9"
        ],
        "ansible_default_ipv4": {
            "address": "10.32.1.9",
            "alias": "eth0",
            "broadcast": "10.32.1.255",
            "gateway": "10.32.1.1",
            "interface": "eth0",
            "macaddress": "fa:16:3e:cb:d6:e1",
            "mtu": 1500,
            "netmask": "255.255.255.0",
            "network": "10.32.1.0",
            "type": "ether"
        }
    },
    "changed": false
}

Ali Jabir

unread,
Nov 19, 2016, 1:10:29 PM11/19/16
to ansible...@googlegroups.com
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

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Vikram Ranabhatt

unread,
Nov 19, 2016, 1:55:46 PM11/19/16
to Ansible Project
HI Ali,

I added gather_facts: yes but no luck

---
- hosts: all
  gather_facts
: yes


  tasks
:


 
- name: vikram
#    debug: msg="vikram"
   
#debug: msg={{ hostvars[item] }}
    debug
: msg={{ hostvars[item]['ansible_default_ipv4']['address'] }}
    with_items
:
     
- "{{ groups['all'] }}"




Output:

root@installterinceptionvm2:/home/ubuntu/ansible# ansible-playbook -i inventory/inventory test1.yml



PLAY
[all] *********************************************************************


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}


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"}
        to
retry, use: --limit @/home/ubuntu/ansible/test1.retry


PLAY RECAP
*********************************************************************
edge
-instance-1 : ok=0    changed=0    unreachable=1    failed=0
edge
-instance-2 : ok=0    changed=0    unreachable=1    failed=0
inception      
: ok=1    changed=0    unreachable=0    failed=1
kuberenetes
-master-1 : ok=0    changed=0    unreachable=1    failed=0
kuberenetes
-master-2 : ok=0    changed=0    unreachable=1    failed=0
kuberenetes
-master-3 : ok=0    changed=0    unreachable=1    failed=0
kuberenetes
-node-1 : ok=0    changed=0    unreachable=1    failed=0
kuberenetes
-node-2 : ok=0    changed=0    unreachable=1    failed=0
kuberenetes
-node-3 : ok=0    changed=0    unreachable=1    failed=0
kuberenetes
-node-4 : ok=0    changed=0    unreachable=1    failed=0
kuberenetes
-node-5 : ok=0    changed=0    unreachable=1    failed=0
openam
-instance : ok=0    changed=0    unreachable=1    failed=0
opendj
-instance : ok=0    changed=0    unreachable=1    failed=0



Kai Stian Olstad

unread,
Nov 19, 2016, 2:18:55 PM11/19/16
to ansible...@googlegroups.com
On 19. nov. 2016 19:55, Vikram Ranabhatt wrote:
> ---
> -hosts:all
> gather_facts:yes
> tasks:
> -name:vikram
> # debug: msg="vikram"
> #debug: msg={{ hostvars[item] }}
> debug:msg={{hostvars[item]['ansible_default_ipv4']['address']}}
> with_items:
> -"{{ 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"}
> 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() }}


--
Kai Stian Olstad

vikram ranabhatt

unread,
Nov 19, 2016, 3:16:31 PM11/19/16
to ansible...@googlegroups.com

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??


--
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/lpDuUpqdnys/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.

To post to this group, send email to ansible-project@googlegroups.com.

Kai Stian Olstad

unread,
Nov 19, 2016, 3:30:24 PM11/19/16
to ansible...@googlegroups.com
On 19. nov. 2016 21:16, vikram ranabhatt wrote:
> 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??

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.

--
Kai Stian Olstad

Ali Jabir

unread,
Nov 19, 2016, 8:46:34 PM11/19/16
to ansible...@googlegroups.com
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



--
Kai Stian Olstad

--
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-project+unsubscribe@googlegroups.com.

To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages