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

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

- name: "Distribute public key of tunnel user"
  authorized_key:
    user='{{ tunnel_user_name }}'
    key="{{ pubkey.stdout }} {{ inventory_hostname }}"
    path='/home/{{ tunnel_user_name }}/.ssh/fresh_auth_keys_tunnel_{{ inventory_hostname }}'
  delegate_to: '{{ item }}'
  with_items: '{{ groups.all }}'
  when: item != "localhost" and inventory_hostname != "localhost"
