Reputation:
Below is my host file /etc/ansible/hosts
root@ubuntu:/home/dasitha# cat /etc/ansible/hosts
[web]
10.0.0.112 ansible_user=root
[local]
127.0.0.1 ansible_user=root
When I execute ansible all -m ping -vv
below error throws.
ansible 2.5.3
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.6 (default, Jun 22 2015, 18:00:18) [GCC 4.8.2]
Using /etc/ansible/ansible.cfg as config file
META: ran handlers
10.0.0.112 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n",
"unreachable": true
}
127.0.0.1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n",
"unreachable": true
}
Upvotes: 2
Views: 13733
Reputation: 196
Ansible assumes you’re using passwordless (key-based) login for SSH. If you insist on using passwords, add the --ask-pass ( -k )
flag to Ansible commands (you may also need to install the sshpass
package for this to work).
$ sudo apt-get install sshpass
ansible server-group -m ping -k -u username
SSH password:
Upvotes: 1
Reputation: 6685
since the ssh works between the ansible controller and the remote machine(s), its probably due to ssh rejecting the login due to failed authentication ways. you probably haven't exchanged ssh keys for passwordless login, and with your command you didnt provide the password either.
To provide in ad-hoc commands, like the one you tried, the password, you pass the --ask-pass
flag at the end:
[ilias@optima-ansible ~]$ ansible greenhat -m ping --ask-pass
SSH password:
greenhat | SUCCESS => {
"changed": false,
"ping": "pong"
}
[ilias@optima-ansible ~]$
without flag:
[ilias@optima-ansible ~]$ ansible greenhat -m ping
greenhat | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ilias@greenhat: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
"unreachable": true
}
[ilias@optima-ansible ~]$
hope it helps
Upvotes: 3