Using ansbile and ansbile-playbook with just the password for the remote host

I’m new to Ansible. I know I can add the ssh keys to the remote host(s) and that works. But I was wondering if there is a way to do it without sharing keys and just putting a password every time the Ansible playbook is executed.

I tried the following and they don’t work.

$ansible myhost -m ping -i ansibile_hosts -u myuserid --private-key=~/.ssh/mykey_rsa --ask-pass

$ansible myhost -m ping -i ansibile_hosts -u myuserid --ask-pass

Thanks.
-Soumya

Could you please explain how they’re not working? Using --ask-pass is the correct option to have Ansible prompt you for a password. If you’re using SSH as your connection type (or “smart”, on a system that is not RHEL/CentOS 6), you can also add -vvvv to get SSH debugging info printed out.

If I do a normal ssh to the machine it works.
$ssh myhost
user@myhost’s password:

Last login: Thu Oct 10 13:15:40 2013 from xxxxxxxx

However when I do any of the following:

$ansible myhost -m ping -i ansibile_hosts -u myuserid --private-key=~/.ssh/mykey_rsa --ask-pass -vvvv

$ansible myhost -m ping -i ansibile_hosts -u myuserid --ask-pass -vvvv

this what I get, I’m using the same password as I used for my ssh login above.

SSH password:
<x.x.x.x> ESTABLISH CONNECTION FOR USER: myuserid
x.x.x.x | FAILED => to use the ‘ssh’ connection type with passwords, you must install the sshpass program

Do I really need sshpass for this work ? I’m on a OS-X (12.5.0 Darwin Kernel Version 12.5.0: Mon Jul 29 16:33:49 PDT 2013; root:xnu-2050.48.11~1/RELEASE_X86_64 x86_64) and looks like it’s not easy to install sshpass using port or brew.

Thanks.

Yes, unfortunately that is a requirement when using the --ask-pass option.

Thanks.

Hi,

I am facing a similar issue.
I have non-root access to a server to which i am able to connect manually.
But ansible throws “to use the ‘ssh’ connection type with passwords, you must install the sshpass program” error when i execute the playbook.
My hosts file contains the ip address and credentials to login to that server in the below format
ip ansible_ssh_user=“non-root-user” ansible_ssh_pass=“password”

Is it necessary to install sshpass on the remote node as well??

I do not have root access, so how do i go about it?

Please suggest ASAP

Thanks in advance,
Mona G

Not on the remote node, but you need sshpass on your Ansible control machine.

Hi Kai,

I have installed openssh-server and openssh-clients on the control machine and the error still persists.
Any other way forward??

Did you install the package "sshpass" on the control machine? (Non-interactive ssh password authentication).
Ansible doesn't require openssh-server on the control machine, but when you are using ssh with password the program "sshpass" is needed on the control machine since ssh doesn’t provide this functionality itself.

Hi Kai,

I have installed openssh-server and openssh-clients on the control machine using yum.
And still getting the error: | FAILED => to use the ‘ssh’ connection type with passwords, you must install the sshpass program

Regards,
Mona G