loop_control with with_together

Hi,

I have two sets of data:

set1 = [ 1, 2 ]
set2 = [ [‘a’,‘b’,‘c’], [‘d’,‘e’] ]

For every element from set1 I need to perform a task with parameters from set2. So I need to perform tasks with following parameters:

task(1,a)
task(1,b)
task(1,c)
task(2,d)
task(2,e)

I can loop over elements of set2 using loop_control:

Outer loop:

  • include: subtasks/dwnfiles.yml
    with_items: “{{ set2 }}”
    loop_control:
    loop_var: s2_elements

Inner loop:

  • debug:
    msg: “inner item={{ item }}”
    with_items:
    “{{ s2_elements }}”

This works fine, but how can I pass to the inner loop values from set1? Is it possible to use somehow with_together here? Something like that:

Outer loop:

  • include: subtasks/dwnfiles.yml
    with_together:
    “{{ set1 }}”
    “{{ set2 }}”
    loop_control:
    loop_var: s1_element
    loop_var: s2_elements

Inner loop:

  • debug:
    msg: “outer from set1={{ s1_element }} inner item={{ item }}”
    with_items:
    “{{ s2_elements }}”

Or may be there’s another solution?

Best Regards,
Ivan

I resolved this by myself.
with_together can be used with loop_control. In this case loop_var is build as array [ item.0, item.1 ]. In my case in the inner loop will passed following valuse [ set1.0 set2.0], [ set1.1 set2.1] and so on ( [1, a, b, c], [2, d, e]). The Inner loop I built as as loop with with_indexed_items and I do not do anything when index == 0 and use first element of the array as an element from set1.