We have two lists. Which can have any amount of items.
vrfs:
- name: vrf1
id: 11
- name: vrf2
id: 12
- name: vrf3
id: 13
interfaces:
- vlan
- gigabit1.
And we have a task with a loop, in which we want to combine these lists, separately, based on the ID of vrfs list and use this same ID and name in the task as well so the output would be in each loop cycle as follows:
1st cycle:
11
vrf1
vlan11
gigabit1.11
2nd cycle:
12
vrf2
vlan12
gigabit1.12
3rd cycle:
13
vrf3
vlan13
gigabit1.13
I have tried all kinds of nested loop variations so far, but none achieve the described outcome, because in the usual nested loop:
loop: "{{ vrfs|product(interfaces)|list }}"
Everything is iterated one by one, meaning we first iterate item 1 of vrfs & item 1 of interfaces, but I need to iterate all items of the interfaces list at once in the inner loop.
inclue_tasks would solve this, since I could combine the IDs and interfaces into a temporary list variable in the inner loop in one shot, with something like this:
- name: Initialize an empty list
set_fact:
interfaces_combined: []
- name: Combine interface prefixes with VRF IDs
set_fact:
interfaces_combined: "{{ interfaces_combined + [ item + outer.item.id|string ] }}"
loop: "{{ interfaces }}"
But I can not run include_tasks and the other module I need to use in outer loop.
Any ideas?