Ansible tries to connect to host that is not in inventory

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 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: ssh: Could not resolve hostname 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 /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.

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

ansible-config dump | grep HOST_LIST

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 /data/ansible/hosts

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.

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