---
# file: roles/commonkeys/tasks/admin_keys.yml

- name: "Read public key of admin user"
  shell: cat /home/{{ username }}/.ssh/id_rsa.pub
  register: pubkey

- name: "Distribute public key of admin user"
  authorized_key:
    user='{{ username }}'
    key="{{ hostvars[item].pubkey.stdout }} {{ item }}"
    path='/home/{{ username }}/.ssh/fresh_auth_keys_tunnel_{{ item }}'
  with_items: '{{ groups.all }}'
  when: item != "localhost" and inventory_hostname != "localhost" and hostvars[item].pubkey is defined
