`ansible_host` parameter doesn't apply to some host

I’m reading the inventory document but can’t follow this example:

Suppose you have just static IPs and want to set up some aliases that live in your host file, or you are connecting through tunnels. You can also describe hosts like this:

 
jumper ansible_port=5555 ansible_host=192.168.1.50

Here is my /etc/ansible/hosts file:

vm1 ansible_host=localhost ansible_connection=local
vm2 ansible_host=192.168.104.102

When I tried to ping every host, I got this error message for vm2:

vagrant@vm1:~$ ansible all -m ping
vm2 | FAILED => SSH Error: ssh: Could not resolve hostname vm2: Name or service not known
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
vm1 | success >> {
“changed”: false,
“ping”: “pong”
}

How can I set an alias for static IP 192.168.104.102 ?

Try using ansible_ssh_host instead:

vm2 ansible_ssh_host=192.168.104.102

Thanks! ansible_ssh_host works.

เมื่อ วันอังคารที่ 13 ตุลาคม ค.ศ. 2015 0 นาฬิกา 04 นาที 05 วินาที UTC+7, Markus Ellers เขียนว่า: