I have 2 arrays
"containers": [
"ContainerA",
"ContainerA",
"ContainerB",
"ContainerB"
]
"apps": [
"app2",
"app1",
"app2",
"app1"
]
I would like to merge them into an array of dictionaries like this ( I assume with set_fact ):
services:
- { container: 'ContainerA', app: 'app2' }
- { container: 'ContainerA', app: 'app1' }
- { container: 'ContainerB', app: 'app2' }
- { container: 'ContainerB', app: 'app1' }
How can I do that?
sivel
(sivel)
December 16, 2015, 8:03pm
2
How do you plan on using this data. Maybe there is a different way to achieve your result, because it won’t be easy or straight forward to get what you want.
Maybe with_together on a task could give you what you want instead:
I plan to use it in a template like so:
{% for source in services %}
container={{source.container}}
app={{source.app}}
{% endfor %}
sivel
(sivel)
December 16, 2015, 9:58pm
4
Perhaps the following will achieve your goal:
{% for source in lookup(‘together’, containers, apps, wantlist=True) %}
container={{ source.0 }}
app={{ source.1 }}
{% endfor %}