Double loop Ansible

Question:

I have an object like that

And I’d like to create the following files

but I have no idea how to do a double loop using with_items

Answer:

Take a look at with_subelements in Ansible’s docs for loops.

  1. You need to create directories:
  2. Iterate though objs and create files:

Here is an example:

An output is pretty self explanatory, the second loop iterates through the values the way you need it:

Leave a Reply