production (inventory file):
#main ansible_host=54.293.2785.210 ansible_port=22 ansible_ssh_user=ubuntu
54.293.2785.210 ansible_ssh_user=ubuntu
Running an ad-hoc command: ansible all -i production -a "hostname"
Works!
But when I uncomment the first line and comment the second:
ansible main -i production -a "hostname" -vvvv
Gives the following error:
main | FAILED => SSH Error: ssh: Could not resolve hostname main: 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.
Why is this not working?
ansible_host
is the new (>=2.0) syntax.
Before that is was simply ansible_ssh_host
but this has been deprecated in the more recent versions of Ansible (>=2.0):
Ansible 2.0 has deprecated the “ssh” from ansible_ssh_user, ansible_ssh_host, and ansible_ssh_port to become ansible_user, ansible_host, and ansible_port. If you are using a version of Ansible prior to 2.0, you should continue using the older style variables (ansible_ssh_*). These shorter variables are ignored, without warning, in older versions of Ansible.
If you're using an earlier version of Ansible then ansible_ssh_host
should work for you.