From 7d6b98e708f9f468a54cfb114bf45cc63a69b9bd Mon Sep 17 00:00:00 2001 From: binary Date: Sun, 6 Dec 2020 15:15:10 +0100 Subject: Add dynamic ssh keys for users based on implicit directories --- files/pubkeys/puffy/rgoncalves.pub | 1 + roles/sshd/tasks/main.yml | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 120000 files/pubkeys/puffy/rgoncalves.pub diff --git a/files/pubkeys/puffy/rgoncalves.pub b/files/pubkeys/puffy/rgoncalves.pub new file mode 120000 index 0000000..f869ceb --- /dev/null +++ b/files/pubkeys/puffy/rgoncalves.pub @@ -0,0 +1 @@ +../rgoncalves.pub \ No newline at end of file diff --git a/roles/sshd/tasks/main.yml b/roles/sshd/tasks/main.yml index 0969429..8c032ee 100644 --- a/roles/sshd/tasks/main.yml +++ b/roles/sshd/tasks/main.yml @@ -12,6 +12,27 @@ group: "{{ group_root }}" mode: 0644 +- name: get ssh keys for all user + find: + paths: "{{ inventory_dir }}/files/pubkeys" + pattern: "*.pub" + recurse: true + file_type: link + register: keys + delegate_to: localhost + +- name: show pubkeys + debug: + var: keys + +- name: synchronize ssh keys + ansible.posix.authorized_key: + user: "{{ item.path | dirname | basename }}" + state: present + key: "{{ lookup('file', item.path) }}" + ignore_errors: true + loop: "{{ keys.files }}" + - name: restart sshd service: name: sshd -- cgit v1.2.3