2

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?

Michael
  • 21
  • 1
  • 3
  • 1
    if you read the errormessage, it says you should install the sshpass program. So you could take the explanation from https://stackoverflow.com/questions/32255660/how-to-install-sshpass-on-mac – Oliver Gaida Jul 12 '22 at 21:09
  • 1
    This seems odd to me. Especially, when I tried to brew and search for sshpass: "If you meant "sshpass" specifically: We won't add sshpass because it makes it too easy for novice SSH users to ruin SSH's security." – Michael Jul 12 '22 at 21:14
  • Then don't use a password with ssh in Ansible. Else install sshpass as very clearly asked. – Zeitounator Jul 12 '22 at 22:31
  • 1
    I find it odd because brew tells me that sshpass is suspicous. Then, I ask myself whether I am doing something wrong in my Ansible yaml instruction set. It seems to be a corner case which in addition, I cannot believe that this is a rare occasion. – Michael Jul 15 '22 at 19:50

0 Answers0