Secondary loop

Hi,

I was wondering if there is an idiomatic way to have a secondary loop in a with_items stanza.

I am trying to template the following directory structure:

/opt/my_app/instance-1/foo.cfg
/opt/my_app/instance-1/bar.cfg
/opt/my_app/instance-1/baz.cfg

/opt/my_app/instance-2/foo.cfg
/opt/my_app/instance-2/bar.cfg
/opt/my_app/instance-3/baz.cfg

…………

/opt/my_app/instance-n/foo.cfg
/opt/my_app/instance-n/bar.cfg
/opt/my_app/instance-n/baz.cfg

So in my playbook to create the {foo.cfg,bar.cfg,baz.cfg} trio, I’ve got this fragment:

action: template src=templates/$item.j2 dest=/opt/my_app/instance_1/$item
with_items:

  • foo.cfg
  • bar.cfg
  • baz.cfg

Is there a neat way that I could create an outer loop of 1…n that I could bind my instance_$i subdirectory to?

Cheers,

Ben

Sorry about the noise on the list, I’ve found that there is actually a solution for this:

https://github.com/ansible/ansible/blob/devel/examples/playbooks/loop_nested.yml

Yep, with_nested is new as of last week!

Let me know if you have any questions about it, we typically document
things in the official docs close to release time, so that will be in
there shortly!