I am trying to copy my .pub key file located in ~/.ssh/mykey.pub to one of the remote hosts using Ansible.
I have a very simple playbook containing this task:
- name: SSH-copy-key to target
hosts: all
tasks:
- name: Copying local SSH key to target
ansible.posix.authorized_key:
user: '{{ ansible_user_id }}'
state: present
key: "{{ lookup('file', '~/.ssh/mykey.pub') }}"
Due to the fact that the host is 'new', I am adding a --ask-pass parameter to be asked for the SSH password on the first connection attempt. However, I receive the error that I need to install the sshpass program.
The following is being returned:
➜ ansible ansible-playbook -i inventory.yaml ssh.yaml --ask-pass
SSH password:
PLAY [SSH-copy-key to target] ********************************************************************
TASK [Gathering Facts] ***************************************************************************
fatal: [debian]: FAILED! => {"msg": "to use the 'ssh' connection type with passwords or pkcs11_provider, you must install the sshpass program"}
PLAY RECAP ***************************************************************************************
debian : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
➜ ansible
I am executing Ansible from a MacBook. I tried replacing the 'key' key with the URL to my github account. The same error appears.
key: https://github.com/myuseraccount.keys
Any ideas?