# Can you use with\_nested with with\_together?

**URL:** <https://forum.ansible.com/t/can-you-use-with-nested-with-with-together/13438>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 10, 2013, 12:11am UTC](https://forum.ansible.com/t/can-you-use-with-nested-with-with-together/13438 "2013-09-10T00:11:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Lieberman](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Michael\_Lieberman](https://forum.ansible.com/u/Michael_Lieberman)\
**Post date:** [September 10, 2013, 12:11am UTC](https://forum.ansible.com/t/can-you-use-with-nested-with-with-together/13438/1 "2013-09-10T00:11:24Z")

</div>

I’m trying to have nested looping but I also want one of the lists to only be run through once. e.g. if i had 3 lists x=[‘a’, ‘b’] y=[‘1’] z=[‘A’, ‘B’] I would do something like:

with\_together:

- [‘a’, ‘b’]
- with\_nested:
- [‘1’]
- ['A,‘B’]

and what should come out is:

[‘a’,‘1’,‘A’]  
[‘b’,‘1’,‘B’]

I tried a few variations of the above but it doesn’t seem to work that way. Is there a way to currently do this?

In python it would be something similar to:

import itertools

x=[‘a’,‘b’]  
y=[‘1’]  
z=[‘A’,‘B’]

a=list(itertools.product(y,z))  
b=[i for i in a]  
c=zip(x,b)  
d=

for sublist in c:  
d.append(list(itertools.chain.from\_iterable(sublist)))

The practical end goal of this is I am creating a bunch of new EBS volumes based off of snapshots in EC2 (using the ec2\_vol module) and want to attach them to an instance without reusing the same snapshot twice and being able to list the device names they should be bound to e.g.

[/dev/sdf, /dev/sdg]  
[aws-id-123]  
[snapshot-id-0001, snapshot-id-0002]

gets transformed to:  
[/dev/sdf, aws-id-123, snapshot-id-0001]  
[/dev/sdg, aws-id-123, snapshot-id-0002]

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [September 10, 2013, 9:56am UTC](https://forum.ansible.com/t/can-you-use-with-nested-with-with-together/13438/2 "2013-09-10T09:56:44Z")

</div>

​Currently this is not possible, but there's a feature request for it as of  
yesterday: [https://github.com/ansible/ansible/issues/4060](https://github.com/ansible/ansible/issues/4060)  
and I'm currently working on it 🙂

BTW, I'll like your syntax style, with repeated with\_, better than what's  
in the ticket proposal; seems more consistent​; thoughts, Michael?

Serge

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 10, 2013, 12:34pm UTC](https://forum.ansible.com/t/can-you-use-with-nested-with-with-together/13438/3 "2013-09-10T12:34:11Z")

</div>

Strongly disagree and prefer svg’s suggestion.

I don’t want arbitrary levels of nesting and it will cause people to try things that won’t work.
