ThorneLabs

Ansible OS X Mavericks You Must Install the sshpass Program

• Updated January 21, 2019


While bootstraping a new Rackspace Public Cloud Server with Ansible 1.4.4 on OS X Mavericks, I received an error when running ansible-playbook bootstrap.yml --user root --ask-pass.

The error encountered was:

[11:48:04][user@host][playbooks] ansible-playbook bootstrap.yml --user root --ask-pass
SSH password: 

PLAY [newservers] ************************************************************* 

GATHERING FACTS *************************************************************** 
fatal: [127.0.0.1] => to use the 'ssh' connection type with passwords, you must install the sshpass program

Ansible uses sshpass when logging in to a server via SSH using a password. Apparently, Apple removed sshpass and merged its functionality into the ssh, scp, and ssh-add commands.

For security reasons, you should have Ansible logging in to servers using SSH keys, but for new servers it is simpler to initially log in with a password, have Ansible setup your users and SSH keys, then have subsequent logins use SSH keys.

To get past the sshpass error, you can install sshpass from source code with the following steps:

  1. Install Xcode from the App Store.

  2. Once Xcode is installed, download and install the Command Line Tools by opening Xcode > opening Xcode’s Preferences > clicking the Downloads tab > clicking Command Line Tools > and finally clicking the Install button.

  3. Once the Command Line Tools are installed, download and un-tar the sshpass source code:

     cd ~/Downloads
    
     curl -O -L http://downloads.sourceforge.net/project/sshpass/sshpass/1.05/sshpass-1.05.tar.gz
    
     tar xvzf sshpass-1.05.tar.gz
    
     cd sshpass-1.05
    
  4. Configure, make, and install the sshpass binary:

     ./configure
    
     make
    
     sudo make install
    

Now, re-running ansible-playbook bootstrap.yml --user root --ask-pass will work without a problem.

The steps in this post are no longer necessary if you are running Ansible 1.9.2 or newer. This issue was probably fixed in a version prior to Ansible 1.9.2, but I don’t know which version.