Failed to connect to the host via ssh: user@IP: Permission denied (publickey,password).”

I tried to ping all servers in Ansible

This is what I have in /etc/ansible/hosts file

[webservers]
192.168.1.139

My ping command failed.

$ ansible webservers -m ping
192.168.10.139 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: pandian@192.168.10.139: Permission denied (publickey,password).",
    "unreachable": true
}

I updated the hosts file with credentials.

[webservers]
192.168.1.139 ansible_ssh_pass=password ansible_ssh_user=myuser

Does it work? Not yet

$ ansible webservers -m ping
192.168.10.139 | FAILED! => {
    "msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"
}

I need to install

$ sudo apt-get install sshpass

Finally it works!

$ ansible webservers -m ping
192.168.1.139 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top