used 'product' filter to avoid nested loop for host/group server address and SSH public key paths

This commit is contained in:
2026-06-04 07:59:26 -04:00
parent 0e0120588a
commit e2128552b9

View File

@@ -89,18 +89,16 @@
vars:
ansible_user: root
loop: "{{ groups[instance] | default(hostvars[instance]) }}"
# @TODO find way to incorporate use of 'groups[instance] | default(hostvars[instance]' for
# looping without loop nesting in below task
- name: Providing authorized keys for server root account
delegate_to: "{{ (groups[instance] | default(hostvars[instance]))[0] }}"
delegate_to: "{{ item[0] }}"
delegate_facts: true
remote_user: root
ansible.posix.authorized_key:
user: "{{ ansible_user }}"
key: "{{ lookup('file', item) }}"
key: "{{ lookup('file', item[1]) }}"
state: present
vars:
ansible_user: root
loop: "{{ root_pubkey_paths }}"
loop: "{{ (groups[instance] | default(hostvars[instance])) | product(root_pubkey_paths) }}"
tags:
- lan