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

On Nov 20, 2016 12:48 AM, "Kai Stian Olstad" <
[email protected]> wrote:

> 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
>
> --
> 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/to
> pic/ansible-project/lpDuUpqdnys/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/ansible-project/f4ac8165-35b5-a062-2ea1-ab4383f85897%40olstad.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAGuwZWSrp8_i%3DbyUsU4AcXSHz_Xa-p-k9ELQoLstV_fgUGHBoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to