I'm using homebrew to install Ansible on macOS Catalina (I previously installed via pip too per the documentation). The problem is that when I attempt to use a test playbook, I receive the following error:
target1 | FAILED! => {
"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"
}
The issue is that sshpass isn't readily available on macOS via homebrew, etc. I've found a couple of options of installation for this but attempted to make the following changes prior to installing this:
export ANSIBLE_HOST_KEY_CHECKING=False
host_key_checking=false within the ansible.cfg in the same directory
None of the above changes worked, should I just install sshpass, or is there another workaround? Or should I just use virtualbox and call it a day?
For reference, this is the following playbook, it's a simple ping test that I'm attempting to use on a local Raspberry Pi that I've already been able to SSH into:
-
name: Test connectivity to target servers
hosts: all
tasks:
- name: Ping test
ping:
The inventory.txt file looks like this:
target1 ansible_host=192.168.x.x ansible_ssh_pass=<password>
For other people who may find this useful
This one-liner is all you need (if your macos, already have build-tools installed).
(I suggest that you keep that in a fast access solution, raycast snippets are a good place)
mkdir sshpass-install-temp; cd sshpass-install-temp; curl -L https://sourceforge.net/projects/sshpass/files/latest/download -o sshpass-latest.tar.gz; tar xvzf sshpass-latest.tar.gz; version=$(ls | grep -oE '^sshpass-[0-9.]+'); echo "\033[1;33mInstalling latest version: $version \033[0m"; cd $version; ./configure; make; echo "sudo make install"; sudo make install; cd ../../; rm -R sshpass-install-temp; echo "\033[1;33mInstallation done successfully\033[0m"
The link to the latest release download is
https://sourceforge.net/projects/sshpass/files/latest/download
Check the whole line commands to get the steps.
sshpass-1.10)version variableInstalling latest version: sshpass-1.10 in yellow (\033[1;33m for yellow, \033[0m for the color reset back to normal)./configure on itmake on it
sudo make install (require password)
'/usr/local/share/man/man1'(You can use the link and go to the website as well, then follow the same steps after)
curl -LOJ https://sourceforge.net/projects/sshpass/files/latest/download
tar xvzf sshpass-1.10.tar.gz
ls | grep sshpasscd sshpass-1.10
Run configuring (needed for build)
./configure
Build with
make
Install with
sudo make install
MakeFile (that would be used with make to build)More details below
checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /opt/homebrew/bin/gmkdir -p
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for wchar.h... yes
checking for minix/config.h... no
checking for vfork.h... no
checking for sys/select.h... yes
checking for sys/socket.h... yes
checking whether it is safe to define __EXTENSIONS__... yes
checking whether _XOPEN_SOURCE should be defined... no
checking for gcc... (cached) gcc
checking whether the compiler supports GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to enable C11 features... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for fcntl.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for sys/ioctl.h... yes
checking for unistd.h... (cached) yes
checking for termios.h... yes
checking for an ANSI C-conforming const... yes
checking for pid_t... yes
checking for ssize_t... yes
checking for fork... yes
checking for vfork... yes
checking for working fork... yes
checking for working vfork... (cached) yes
checking how to run the C preprocessor... gcc -E
checking whether gcc needs -traditional... no
checking build system type... aarch64-apple-darwin22.6.0
checking host system type... aarch64-apple-darwin22.6.0
checking for GNU libc compatible malloc... yes
checking types of arguments for select... int,fd_set *,struct timeval *
checking return type of signal handlers... void
checking for select... yes
checking for posix_openpt... yes
checking for strdup... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
Output
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-am
gcc -DHAVE_CONFIG_H -I. -I/opt/homebrew/opt/ruby/include -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
mv -f .deps/main.Tpo .deps/main.Po
gcc -g -O2 -L/opt/homebrew/opt/ruby/lib -o sshpass main.o
output after running
sudo make install
/opt/homebrew/bin/gmkdir -p '/usr/local/bin'
/opt/homebrew/bin/ginstall -c sshpass '/usr/local/bin'
/opt/homebrew/bin/gmkdir -p '/usr/local/share/man/man1'
/opt/homebrew/bin/ginstall -c -m 644 sshpass.1 '/usr/local/share/man/man1'