title: Call ssh-copy-id in an Ansible playbook - How to handle password prompt?
body: <p>I have two servers. I manage <code>serverA</code> with Ansible. <code>serverB</code> is not managed with Ansible. I want <code>serverA</code> to be able to access <code>serverB</code> by copying the <code>ssh_pub_key</code> of <code>serverA</code> to <code>serverB</code>.</p>
  
  <p>This can be done manually by calling <code>ssh-copy-id user@serverB</code> on <code>serverA</code>.</p>
  
  <p>I want to do this with Ansible on <code>serverA</code> automatically.</p>
  
  <pre><code>- name: Register ssh key at serverB
    command: ssh-copy-id -i /home/{{user}}/.ssh/id_rsa.pub -o StrictHostKeyChecking=no user@serverB
  </code></pre>
  
  <p>Calling <code>ssh-copy-id</code> requires me to enter my ssh password for user@serverB, so the key can be copied.</p>
  
  <p>How can I do this via ansible? I want it to ask for the user@serverB password interactively while executing the playbook. Storing the password in ansible vault is also an option. Then I still do not know how to avoid the interactive password call of <code>ssh-copy-id</code> though.</p>
  
  <p>I also added <code>-o StrictHostKeyChecking=no</code> to the call because this is another interaction that normally requires user interaction when calling ssh-copy-id.</p>