From 970a107492c31a43bb77f6f5e0096b41adc2c2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Mon, 12 Dec 2022 22:51:55 +0100 Subject: refactor: split sshd and ssh key synchronization --- roles/sshd_keys/meta/main.yml | 5 +++++ roles/sshd_keys/tasks/main.yml | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 roles/sshd_keys/meta/main.yml create mode 100644 roles/sshd_keys/tasks/main.yml (limited to 'roles/sshd_keys') diff --git a/roles/sshd_keys/meta/main.yml b/roles/sshd_keys/meta/main.yml new file mode 100644 index 0000000..46c62ed --- /dev/null +++ b/roles/sshd_keys/meta/main.yml @@ -0,0 +1,5 @@ +--- + +dependencies: + - role: sshd + tags: dependency diff --git a/roles/sshd_keys/tasks/main.yml b/roles/sshd_keys/tasks/main.yml new file mode 100644 index 0000000..32f6b5a --- /dev/null +++ b/roles/sshd_keys/tasks/main.yml @@ -0,0 +1,20 @@ +--- + +- name: get ssh keys for all users + ansible.builtin.find: + paths: files/keys + file_type: link + recurse: true + delegate_to: localhost + run_once: true + register: result + +- name: synchronize ssh keys + ansible.posix.authorized_key: + user: "{{ item.path | dirname | basename }}" + state: present + key: "{{ lookup('file', item.path) }}" + loop_control: + label: "{{ item.path }} -> user: {{ item.path | dirname | basename }}" + loop: "{{ result.files }}" + failed_when: false -- cgit v1.2.3