SSH: Template authorized_keys file
This commit is contained in:
parent
547b1373c3
commit
af54b8ce71
@ -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
|
||||
|
4
ansible/plays/templates/authorized_keys.j2
Normal file
4
ansible/plays/templates/authorized_keys.j2
Normal file
@ -0,0 +1,4 @@
|
||||
{{ machine_key }}
|
||||
{% for key in common.ssh.authorized_keys %}
|
||||
{{ key }}
|
||||
{% endfor %}
|
Loading…
Reference in New Issue
Block a user