# Gather Facts failed due resolve hostname inventory\_hostname

**URL:** <https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045>\
**Category:** Ansible Project\
**Created:** [June 1, 2023, 6:42pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045 "2023-06-01T18:42:59Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bikram](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Bikram](https://forum.ansible.com/u/Bikram)\
**Post date:** [June 1, 2023, 6:42pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/1 "2023-06-01T18:42:59Z")

</div>

Hello Team,

I am trying to run a playbook to gather facts from a nexus switch but playbook run throws an error: ‘Failed to resolve hostname inventory\_hostname’

However, in the debug message, I can see the inventory\_hostname.

Here is my host file:

[all]

NEXUS3172P ansible\_ssh\_host=10.131.88.10 ansible\_network\_os=nxos username=xxxx password=xxxxx

Below is the section of the tasks where I am getting error:

- name: ‘{{ msg\_block }} Set CLI parameters’  
set\_fact:  
cli:  
host: ‘{{ inventory\_hostname }}’  
username: ‘{{ username }}’  
password: ‘{{ password }}’  
timeout: 21600  
no\_log: true

- name: ‘{{ msg\_block }} Gather hardware info’  
block:

- name: ‘{{ msg\_block }} Gather hardware info’  
nxos\_facts:  
gather\_subset: hardware  
provider: ‘{{ cli }}’  
register: device\_facts

[bkb1321@ansible-server playbooks]$ ansible-playbook image\_copy\_nexus.yaml -i ../hosts

Enter your finastra email: hh

PLAY [Copy image to network device] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [NEXUS3172P] =\> {

“inventory\_hostname”: “NEXUS3172P”

}

TASK [NEXUS3172P Normalize variables] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [NEXUS3172P]

TASK [NEXUS3172P Debug normalized variables] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [NEXUS3172P]

TASK [NEXUS3172P image\_copy\_cisco\_nexus.yaml] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

included: /etc/ansible/playbooks/play\_image\_copy\_nexus.yaml for NEXUS3172P

TASK [NEXUS3172PSet CLI parameters] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [NEXUS3172P]

TASK [NEXUS3172P Gather hardware info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [NEXUS3172P]: FAILED! =\> {“ansible\_facts”: {“discovered\_interpreter\_python”: “/usr/bin/python3”}, “changed”: false, “msg”: “ssh connection failed: ssh connect failed: Failed to resolve hostname inventory\_hostname (Name or service not known)”}

TASK [set\_fact] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [NEXUS3172P]

Any help is much appreciated.

Thank you.

Bikram

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 1, 2023, 6:45pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/2 "2023-06-01T18:45:47Z")

</div>

I believe the message is about DNS resolution, if the inventory\_hostname is not DNS resolvable, try setting the ip or resolvable name in the ansilbe\_host variable in that host’s scope

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [June 1, 2023, 6:56pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/3 "2023-06-01T18:56:59Z")

</div>

Also, does your nxos\_facts task need to “delegate\_to: localhost” and use an API to talk to the “inventory\_hostname” target?

Walter

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 1, 2023, 6:58pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/4 "2023-06-01T18:58:53Z")

</div>

not if using nxos connection plugin, as it does similar thing in the  
background w/o needing delegation.

---

<div class="post-metadata">

**Author:** ![Bikram](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Bikram](https://forum.ansible.com/u/Bikram)\
**Post date:** [June 1, 2023, 7:10pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/5 "2023-06-01T19:10:53Z")

</div>

Hi Brian,

Even I tried with the following in host file but the error is same:

[all]

10.131.88.10 ansible\_ssh\_host=10.131.88.10 ansible\_network\_os=nxos username=xxxx password=xxxxx

It seems ansible is treating ‘inventory\_hostname’ as a hostname.

In fact it knows the inventory\_hostname as you see from my playbook-run debug output.

Thanks

Bikram

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 1, 2023, 7:39pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/6 "2023-06-01T19:39:17Z")

</div>

by default, ansilbe will use inventory\_hostname as the hostname, only  
if ansilbe\_host is present, will it use that.

In any case, ansible itself does not 'resolve' names, it passes it to  
the connection (in this case ssh) which seems to complain that it is  
not resolvable.

---

<div class="post-metadata">

**Author:** ![Bikram](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Bikram](https://forum.ansible.com/u/Bikram)\
**Post date:** [June 1, 2023, 7:56pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/7 "2023-06-01T19:56:46Z")

</div>

This is really weird as I can ssh to the host with IP and Hostname.  
Even though I set ansible\_host=10.131.88.10 I am still getting the same error.

Thanks  
Bikram

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [June 1, 2023, 8:49pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/8 "2023-06-01T20:49:39Z")

</div>

In your first post you were setting ansible\_ssh\_host=10.131.88.10, not ansible\_host.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [June 1, 2023, 9:47pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/9 "2023-06-01T21:47:08Z")

</div>

Both are ansible\_host and ansible\_ssh\_host are valid. See  
[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh\_connection.html#parameter-remote\_user](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-remote_user)

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [June 1, 2023, 9:49pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/10 "2023-06-01T21:49:25Z")

</div>

> [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh\_connection.html#parameter-remote\_user](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-remote_user)

Errata

[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh\_connection.html#parameter-host](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-host)

---

<div class="post-metadata">

**Author:** ![Bikram](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Bikram](https://forum.ansible.com/u/Bikram)\
**Post date:** [June 1, 2023, 10:12pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/11 "2023-06-01T22:12:23Z")

</div>

Yeah that’s right. ansible\_host and ansible\_ssh\_host are the same. I tried both options. Weird thing is complaining about dns resolution even after using ip address.

Thanks

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [June 1, 2023, 10:39pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/12 "2023-06-01T22:39:00Z")

</div>

\*ansible\_host\* and \*ansible\_ssh\_host\* are the same when you use  
\*ansible.builtin.ssh\* connection plugin. See  
[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh\_connection.html#parameter-host](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-host)

In your case, \*ansible\_network\_os=nxos\* indicates that you use  
\*ansible.netcommon.network\_cli\* connection plugin. This plugin  
doesn't recognise \*ansible.builtin.ssh\*. See  
[https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/network\_cli\_connection.html#parameter-host](https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/network_cli_connection.html#parameter-host)

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [June 1, 2023, 11:01pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/13 "2023-06-01T23:01:12Z")

</div>

Try to isolate your problem:

\* Create the inventory

> cat hosts

[test]  
NEXUS3172P

[test:vars]  
ansible\_host=10.131.88.10  
ansible\_network\_os=nxos  
username=xxxx  
password=xxxxx

\* Create a simple playbook

> cat pb.yml

- hosts: NEXUS3172P  
&nbsp;&nbsp;gather\_facts: false  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- nxos\_facts:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gather\_subset: hardware

\* Debug the connection (-vvvv)

---

<div class="post-metadata">

**Author:** ![Bikram](https://avatars.discourse-cdn.com/v4/letter/b/f04885/32.png) [@Bikram](https://forum.ansible.com/u/Bikram)\
**Post date:** [June 1, 2023, 11:10pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/14 "2023-06-01T23:10:10Z")

</div>

Thanks a lot Vladimir. I really appreciate your help.

With the following combination it works:  
ansible\_host and connection=ansible.netcommon.network\_cli

Previous setting was:

ansible\_host and connection=local [which actually worked on ansible version 2.9.11 but my current version is 2.13.7]

-Bikram

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 2, 2023, 3:41pm UTC](https://forum.ansible.com/t/gather-facts-failed-due-resolve-hostname-inventory-hostname/38045/15 "2023-06-02T15:41:26Z")

</div>

sorry, got mislead by the error, its quite literally trying to resolve  
`inventory_hostname` not it's value, but the string itself. This was a  
bug in several connection plugins, but both core Ansible and the  
plugins were patched to bypass it, try upgrading core, the collection  
or both.
