I am using vagrant now.
I can ping virtual machine from local terminal.
I want to use ansible to ping that vagrant virtual machine:
$ ansible 192.168.33.101 -m ping -u root
But got error:
192.168.33.101 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n",
"unreachable": true
}
I added that IP in /etc/ansible/hosts
file:
192.168.33.101
Both local and virtual machine have ssh installed. So why can't reach?
Best Answer
You need to configure your ssh connection. The Ansible
ping
module naming is confusing. Theping
module actually builds up an ssh connection to verify the ability to login and that a usable python is configured.So like the
ping command
can tell you that the network connection to a remote host is working theping module
tells you that Ansible is capable of running commands on the remote host.Look at the official documentation how to setup ssh connection to your Vagrant box.
Basically you will need something like this:
For ad-hoc commands something like this: