Ansible: To use the ssh connection type with passwords, you must install the sshpass program

This guide will show you how to fix the following error when running your Ansible Playbook: “to use the ssh connection type with passwords, you must install the sshpass program”.

The error may look something like this:

TASK [Gathering Facts] ******************************************************************************************************************************************************************
fatal: [albus.local]: FAILED! => {"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"}

What is sshpass?

sshpass is a command-line tool that allows you to do non-interactive ssh login.

So how is sshpass different for ssh? Well, ssh uses direct TTY access to ensure that an interactive keyboard user issues the password. However, sshpass runs ssh in a dedicated TTY, tricking ssh into thinking that the password is from an interactive user.

It would be best if you did not use sshpass on a production server. The reason is that sshpass reveals the password to all system users on the command line using the “ps” command.

According to the sshpass man page:

Users of sshpass are encouraged to use one of the other password passing techniques, which are all more secure. In particular, people writing programs that are meant to communicate the password programatically are encouraged to use an anonymous pipe and pass the pipe's reading end to sshpass using the -d option.
YouTube player

So, how do you fix this Ansible error?

Ansible requires sshpass to be able to run ssh commands without prompting passwords. Therefore, you have to install the sshpass package on your Ansible control machine to resolve this error.

Ansible will not prompt for passwords when you:

  • Remove the “ask_pass=True” line in ansible.cfg file.
  • Add the “ansible_ssh_pass=<mypass>” line in the inventory file.

The settings mentioned above will require Ansible to use sshpass. The reason is that Ansible will not prompt you to enter the password manually.

How to install sshpass for Ansible to support ssh passwords?

You can install sshpass on Debian/Ubuntu and its derivatives using the apt-get command:

sudo apt install sshpass

Alternatively, you can install sshpass on RedHat/CentOS using the yum command:

yum install epel-release
yum install sshpass

Wrapping up

You should now be able to run your Ansible Playbook without the “to use the ssh connection type with passwords, you must install the sshpass program” error.

You may also be interested in

About Anto Online

Anto, a seasoned technologist with over two decades of experience, has traversed the tech landscape from Desktop Support Engineer to enterprise application consultant, specializing in AWS serverless technologies. He guides clients in leveraging serverless solutions while passionately exploring cutting-edge cloud concepts beyond his daily work. Anto's dedication to continuous learning, experimentation, and collaboration makes him a true inspiration, igniting others' interest in the transformative power of cloud computing.

View all posts by Anto Online

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.