0Pricing
Ansible Academy · Lesson

Nested Loops with subelements

Iterate lists inside lists.

Lists Inside Lists

Sometimes each item owns its own list: a user with several SSH keys, a group with many members. That is a nested structure. 🪆

The subelements Lookup

The subelements lookup pairs each parent with each child in its inner list, flattening the nesting into single iterations.

loop: "{{ users | subelements('keys') }}"

All lessons in this course

  1. The loop Keyword Over a List
  2. Looping Over Dictionaries
  3. Nested Loops with subelements
  4. loop_control: label, index & pause
← Back to Ansible Academy