title: Ansible passwordless access between nodes
body: <p>To give passwordless access to all nodes for all other nodes.</p>
  
  <pre><code>For each node:   
    Get public ssh key   
    Add that key to authorized_keys files of all other nodes
  </code></pre>
  
  <p>Below is what I tried, but it's not working as expected. </p>
  
  <pre><code>- name: Get ssh public key from all the nodes for some_user user
    shell: cat ~/.ssh/id_rsa.pub
    register: ssh_pub_key
    become: yes
    become_user: some_user
    changed_when: "ssh_pub_key.rc != 0"
    always_run: yes
  
  - set_fact:
      auth_keys: "{{ ssh_pub_key.stdout | join() }}"
  
  - debug: var=auth_keys
  
  - name: Add public key to all other nodes for some_user user
    authorized_key:
      user: some_user
      key: "{{ ssh_pub_key.stdout }}"
  </code></pre>