Can you use with_nested with with_together?

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]

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

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

Serge

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.