# loop\_control with with\_together

**URL:** <https://forum.ansible.com/t/loop-control-with-with-together/24462>\
**Category:** Ansible Project\
**Created:** [May 11, 2017, 1:43pm UTC](https://forum.ansible.com/t/loop-control-with-with-together/24462 "2017-05-11T13:43:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VenomMsk](https://avatars.discourse-cdn.com/v4/letter/v/eb9ed0/32.png) [@VenomMsk](https://forum.ansible.com/u/VenomMsk)\
**Post date:** [May 11, 2017, 1:43pm UTC](https://forum.ansible.com/t/loop-control-with-with-together/24462/1 "2017-05-11T13:43:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![VenomMsk](https://avatars.discourse-cdn.com/v4/letter/v/eb9ed0/32.png) [@VenomMsk](https://forum.ansible.com/u/VenomMsk)\
**Post date:** [May 12, 2017, 9:10am UTC](https://forum.ansible.com/t/loop-control-with-with-together/24462/2 "2017-05-12T09:10:24Z")

</div>

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.
