You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

57 lines
1.4KB

  1. ---
  2. - hosts: servers:desktops:laptops
  3. remote_user: root
  4. roles:
  5. - name: root_user
  6. - name: users
  7. - hosts: desktops:laptops
  8. remote_user: root
  9. tasks:
  10. - fetch:
  11. src: /etc/ssh/ssh_host_ed25519_key.pub
  12. dest: host_files/{{ inventory_hostname }}
  13. - name: /etc/ssh/ssh_config
  14. template:
  15. src: ssh_config.j2
  16. dest: /etc/ssh/ssh_config
  17. - name: /etc/ssh/ssh_known_hosts
  18. template:
  19. src: ssh_known_hosts.j2
  20. dest: /etc/ssh/ssh_known_hosts
  21. mode: 'u=rw,g=r,o=r'
  22. - hosts:
  23. - servers
  24. - desktops
  25. - laptops
  26. remote_user: root
  27. tasks:
  28. - name: fetch ssh public keys
  29. fetch:
  30. src: /home/{{item}}/.ssh/id_ed25519.pub
  31. dest: host_files
  32. fail_on_missing: yes
  33. loop: "{{ users.keys() | list }}"
  34. - name: delete ssh known hosts user files
  35. shell: rm /home/*/.ssh/known_hosts
  36. failed_when: false
  37. - hosts:
  38. - servers
  39. remote_user: root
  40. tasks:
  41. - name: read ssh public keys
  42. local_action: command fish -c 'cat host_files/*/home/{{item}}/.ssh/id_ed25519.pub'
  43. loop: "{{ users.keys() | list }}"
  44. register: _ssh_public_keys
  45. - name: authorize ssh public keys
  46. copy:
  47. content: "{{ _ssh_public_keys | json_query(\"results[?item=='\"+item+\"'].stdout\") | join(\"\n\") }}"
  48. dest: /home/{{item}}/.ssh/authorized_keys
  49. loop: "{{ users.keys() | list }}"