Search code examples
macosansibleansible-2.xansible-inventory

Make Ansible use the right IP


i'm currently having an odd problem with Ansible

I used to change pretty often the IP address of my hosts in my hosts file. Didn't have any problem so far. But now, even though i changed the IP address in my hosts file, Ansible is still using a previous IP.

Here is the content of my hosts file :

[test-host]
test ansible_host=172.16.0.10 ansible_port=22 ansible_user=vagrant ansible_private_key_file=.vagrant/machines/test/virtualbox/private_key

I even specified the hosts file to use when i'm running my playbook :

ansible-playbook playbook.yml -i hosts.file

I already tried to reinstall Ansible, delete the tmp folder.

I saw that if i'm typing ansible-inventory -list i can see the old IP

{
    "_meta": {
        "hostvars": {
            "test": {
                "ansible_host": "192.168.0.10", 
                "ansible_port": 22, 
                "ansible_private_key_file": ".vagrant/machines/test/virtualbox/private_key", 
                "ansible_user": "vagrant"
            }
        }
    },

How can i force Ansible to use the hosts.file instead of this "cache" ?

Thanks.


Solution

  • Run the command with -vvv

    ansible-inventory -vvv --list
    

    At the beginning of the output find all Parsed ... inventory source. Review the sources to find out where does the problematic host come from.