I am not sure about ping, because ping (ICMP) might be disabled.
- Can you ping and get response from that machine?
Also, I think it might help to understand how ansible connects to a remote host. You can read more here
I will try to describe in brief here
- think of ssh - unless instructed ansible will do exactly how you would normally connect a machine using ssh. which means, it will use the key of the user you specified (if not specified, then its the current user). Using an inventory file, you can customize what user you want ansible to connect as, what certificate to use etc etc.
- Example: I have created a simple /etc/ansible/hosts file, where I have mentioned (you can use an inventory file as well)
192.168.33.10 ansible_user=vagrant ansible_ssh_private_key_file=/[directory]/.vagrant/machines/default/virtualbox/private_key
Now I can just run something like
ansible all -a “/bin/echo hello”
which outputs something like
192.168.33.10 | SUCCESS | rc=0 >> hello
if I want to use an inventory file I can just add the same config in a file (lets say example) containing
192.168.33.10 ansible_user=vagrant ansible_ssh_private_key_file=/[directory]/.vagrant/machines/default/virtualbox/private_key
and then use command like
ansible -i example all -a “/bin/echo hello”
Goes without saying that the public key of the user should be located in authorized_keys
on the remote systems. Also, if you want to do something that requires sudo access, then the user that you used must be part of sudoers.