Added task for taking contents from acquired files, added delegation to a task

This commit is contained in:
Alex Tavarez
2025-10-21 14:07:48 -04:00
parent fd8e4e29b6
commit 09cdafc570

View File

@@ -47,6 +47,7 @@
when: not files_mode and ansible_facts["user_id"] == "root"
block:
- name: Acquire list of SSH public keys for sys-admin user
delegate_to: "{{ ssh_keypairs_origin_host }}"
ansible.builtin.find:
paths: "{{ lookup('env', 'HOME') }}/.ssh"
patterns:
@@ -58,10 +59,18 @@
- administrative_user
- admin_ssh
register: ssh_public_keys
- name: Acquire contents of SSH public keys for sys-admin user
delegate_to: "{{ ssh_keypairs_origin_host }}"
ansible.builtin.command:
argv:
- cat
- "{{ item.path }}"
loop: "{{ ssh_public_keys.files }}"
register: ssh_public_keys_contents
- name: Register SSH public keys as sys-admin user's authorized keys
ansible.builtin.lineinfile:
path: "{{ created_admin.home }}/.ssh/authorized_keys"
line: "{{ lookup('ansible.builtin.file', item.path) }}"
line: "{{ item }}"
owner: "{{ created_admin.name }}"
group: "{{ created_admin.name }}"
mode: "0600"
@@ -72,8 +81,8 @@
- default
- administrative_user
- admin_ssh
loop: "{{ ssh_public_keys.files }}"
- name: Register SSH puplic keys as other users' authorized keys
loop: "{{ ssh_public_keys_contents.results }}"
- name: Register SSH public keys as other users' authorized keys
ansible.builtin.copy:
src: "ssh/{{ item.name }}/authorized_keys"
dest: "{{ item.home }}/.ssh/authorized_keys"