propagate nested loop substitution for added data restructuring task using set_facts module #12

Closed
opened 2026-05-30 03:14:10 +00:00 by admin · 0 comments
Owner

When one needs to traverse to separate data structures using a loop, the options are either:

  • Create a nested loop such that there is one loop per self-contained data structure
  • Transform the two data structures into a singular, joined or linked data structure--or create a third data structure with overlapping information

Because Ansible does not have robust or intuitive support for nested loops, I decided in a given case within the roles/init-server/ssh-users.yml file, to rewrite the code thus:

image.png

Other places (such as roles/init-server/spawn.yml) where a similar conundrum may arise, and thus that may benefit from a similar solution, are those that involve grabbing public SSH keys from the active system user running ansible (even if through sudo or change of user), and distributing those public keys to the appropriate users per definitions in group_vars/* and roles/init-server/{vars,defaults}/users@linux.yml. The above image should be a reference solution in those similar scenarios.

Note that manually defined playbook variables local_facts.user_dir and local_facts.user_id will also tend to be of use in these similar cases.

When one needs to traverse to separate data structures using a loop, the options are either: - Create a nested loop such that there is one loop per self-contained data structure - Transform the two data structures into a singular, joined or linked data structure--or create a third data structure with overlapping information Because Ansible does not have robust or intuitive support for nested loops, I decided in a given case within the `roles/init-server/ssh-users.yml` file, to rewrite the code thus: <img width="1097" alt="image.png" src="attachments/372f2932-9dbc-4163-bb5e-4f0a5e348890"> Other places (such as `roles/init-server/spawn.yml`) where a similar conundrum may arise, and thus that may benefit from a similar solution, are those that involve grabbing public SSH keys from the active system user running ansible (even if through sudo or change of user), and distributing those public keys to the appropriate users per definitions in `group_vars/*` and `roles/init-server/{vars,defaults}/users@linux.yml`. The above image should be a reference solution in those similar scenarios. Note that manually defined playbook variables `local_facts.user_dir` and `local_facts.user_id` will also tend to be of use in these similar cases.
108 KiB
admin added this to the debug bootstrapping of armitage milestone 2026-05-30 03:14:57 +00:00
admin added the fix/compatibility_bugfix/semantic_error labels 2026-05-30 03:15:41 +00:00
admin added this to the skato-ansible debugging project 2026-05-30 03:16:00 +00:00
admin self-assigned this 2026-05-30 03:16:06 +00:00
admin pinned this 2026-05-30 03:16:11 +00:00
admin closed this issue 2026-06-10 19:39:37 +00:00
admin unpinned this 2026-06-10 19:39:56 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/skato-ansible#12