SSH: Template authorized_keys file
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone Build is failing

This commit is contained in:
Tobias Manske 2023-09-15 18:00:27 +02:00
parent 547b1373c3
commit af54b8ce71
Signed by: tobias
GPG Key ID: 9164B527694A0709
2 changed files with 13 additions and 15 deletions

View File

@ -20,21 +20,15 @@
register: pubkey
ansible.builtin.command:
cmd: "ssh-keygen -y -f {{ ansible_ssh_private_key_file }}"
- name: Deploy Machine SSH-Key
ansible.posix.authorized_key:
user: "{{ ansible_user }}"
state: present
manage_dir: false
path: "/etc/ssh/authorized_keys/{{ ansible_user }}"
key: "{{ pubkey.stdout }}"
- name: Deploy Common SSH-Keys
ansible.posix.authorized_key:
user: "{{ ansible_user }}"
state: present
manage_dir: false
path: "/etc/ssh/authorized_keys/{{ ansible_user }}"
key: "{{ item }}"
loop: "{{ common.ssh.authorized_keys }}"
- name: Deploy SSH-Keys
vars:
machine_key: "{{ pubkey.stdout }}"
ansible.builtin.template:
src: "authorized_keys.j2"
dest: "/etc/ssh/authorized_keys/{{ ansible_user }}"
owner: root
group: root
mode: '0644'
- name: Ensure authorized_keys ownership
ansible.builtin.file:
state: directory

View File

@ -0,0 +1,4 @@
{{ machine_key }}
{% for key in common.ssh.authorized_keys %}
{{ key }}
{% endfor %}