From e2128552b97014c44803157d559cb94ba6735062 Mon Sep 17 00:00:00 2001 From: Alex Tavarez Date: Thu, 4 Jun 2026 07:59:26 -0400 Subject: [PATCH] used 'product' filter to avoid nested loop for host/group server address and SSH public key paths --- roles/init-server/tasks/spawn.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/roles/init-server/tasks/spawn.yml b/roles/init-server/tasks/spawn.yml index eaa2178..e11e808 100644 --- a/roles/init-server/tasks/spawn.yml +++ b/roles/init-server/tasks/spawn.yml @@ -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