Created
May 17, 2019 10:00
-
-
Save lukasmrtvy/bfbfe9bd48cc1a16a7dc9870c9f30da4 to your computer and use it in GitHub Desktop.
Ansible nested loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: test | |
hosts: localhost | |
gather_facts: false | |
vars: | |
containers: | |
grafana: | |
variables: | |
docker: | |
foo1: "https://etcd/foo1" | |
foo2: "https://etcd/foo2" | |
foo3: "https://etcd/foo3" | |
foo1s: "https://vault/foo1s" | |
foo2s: "https://vault/foo2s" | |
foo3s: "https://vault/foo3s" | |
prometheus: | |
variables: | |
docker: | |
foo4: "https://etcd/foo4" | |
foo5: "https://etcd/foo5" | |
foo6: "https://etcd/foo6" | |
foo4s: "https://vault/foo4s" | |
foo5s: "https://vault/foo5s" | |
foo6s: "https://vault/foo6s" | |
tasks: | |
- name: "Get container name, for example: grafana, key: foo1, value: https://etcd/foo1" | |
debug: | |
msg: "Container name: {{ item.0.key }} Key: {{ item.1.key }} Value: {{ item.1.value }}" | |
vars: | |
foo: "{{ (containers.values() | list) | map(attribute='variables') | map(attribute='docker') | map('dict2items')| list | flatten }}" | |
bar: "{{ containers | dict2items }}" | |
loop: "{{ bar | product(foo) | list }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment