# Ansible tries to connect to host that is not in inventory

**URL:** <https://forum.ansible.com/t/ansible-tries-to-connect-to-host-that-is-not-in-inventory/28574>\
**Category:** Ansible Project\
**Created:** [September 14, 2018, 11:23am UTC](https://forum.ansible.com/t/ansible-tries-to-connect-to-host-that-is-not-in-inventory/28574 "2018-09-14T11:23:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorg\_Kastning](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Jorg\_Kastning](https://forum.ansible.com/u/Jorg_Kastning)\
**Post date:** [September 14, 2018, 11:23am UTC](https://forum.ansible.com/t/ansible-tries-to-connect-to-host-that-is-not-in-inventory/28574/1 "2018-09-14T11:23:03Z")

</div>

Hi,

running the following ad-hoc command using a static inventory file results in one strange event:

`

# ansible --version

ansible 2.6.3  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python2.7/site-packages/ansible  
executable location = /usr/bin/ansible  
python version = 2.7.5 (default, May 31 2018, 09:41:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

# ansible all -m ping

[foo.example.com](http://foo.example.com) | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: ssh: Could not resolve hostname [foo.example.com](http://foo.example.com): Name or service not known\r\n”,  
“unreachable”: true  
}

`

Strange about this event is that the host in question existed in the past but not anymore. It is not in my inventory file.

`

# grep [foo.example.com](http://foo.example.com) /path/to/ansible/hosts

# echo $?

1  
`

Does anyone have an idea where ansible could find information about this host? And how do I get rid of it.

Regards,  
Joerg K.

---

<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:** [September 14, 2018, 12:30pm UTC](https://forum.ansible.com/t/ansible-tries-to-connect-to-host-that-is-not-in-inventory/28574/2 "2018-09-14T12:30:07Z")

</div>

Are you sure you are checking the correct inventory?  
This will give you the information Ansible uses

ansible-config dump | grep HOST\_LIST

---

<div class="post-metadata">

**Author:** ![Jorg\_Kastning](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Jorg\_Kastning](https://forum.ansible.com/u/Jorg_Kastning)\
**Post date:** [September 14, 2018, 12:40pm UTC](https://forum.ansible.com/t/ansible-tries-to-connect-to-host-that-is-not-in-inventory/28574/3 "2018-09-14T12:40:00Z")

</div>

Yes, I’m pretty sure.

`

# ansible-config dump | grep HOST\_LIST

DEFAULT\_HOST\_LIST(/etc/ansible/ansible.cfg) = [u’/data/ansible/hosts’]

# grep [foo.example.com](http://foo.example.com) /data/ansible/hosts

---

<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:** [September 14, 2018, 3:40pm UTC](https://forum.ansible.com/t/ansible-tries-to-connect-to-host-that-is-not-in-inventory/28574/4 "2018-09-14T15:40:39Z")

</div>

Ansible does not make up hosts, so that must be defined somewhere, you  
can run `ansible-inventory --list -p /path/to/playbook` to ensure no  
other files add that (i.e ansible\_ssh\_host: foo.example.com)

The inventory source is not he only place were you can define an  
address, anywhere you can define a variable lets you define the  
ansible\_host/ansible\_ssh\_host/etc to change the target.

---

<div class="post-metadata">

**Author:** ![Jorg\_Kastning](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Jorg\_Kastning](https://forum.ansible.com/u/Jorg_Kastning)\
**Post date:** [September 14, 2018, 4:03pm UTC](https://forum.ansible.com/t/ansible-tries-to-connect-to-host-that-is-not-in-inventory/28574/5 "2018-09-14T16:03:03Z")

</div>

Yes, you are right. And thanks to your advise using `ansible-inventory  
--list` I was able to found my mistake.

It starts with using a bad example. Because foo.example.com is more like  
foo3.example.com. A `grep foo3.example.com` didn't get a result because  
the host was 'hidden' by "foo[0:3].example.com" in my inventory.

Now, I found it, removed it and everything is fine.

Thanks for your support.  
Joerg
