How i can iterate with Ansible on a dict with contain another dict ?
mydict can contain X "foo" and fooX (like foo1) can contain (at least) one or more params "bar".
I can't really change the vars type, which is currently :
mydict: dict
mydict.foo1: dict
mydict.foo1.params: dict
Ansible playbook : localvars.yml
---
- hosts: localhost
connection: local
gather_facts: false
vars:
mydict:
foo1:
dest: /tmp/foo1.txt
content: "foo1"
params:
bar1:
alias: foo1foo
bar2:
alias: foo1foo
foo2:
dest: /tmp/foo2.txt
content: "foo2"
params:
bar1:
alias: foo1foo
tasks:
- name: Print records
debug:
msg: |-
Item {{ item.key }} dest {{ item.value.dest }} content {{ item.value.content }} params {{ item.value.params }}"
loop: "{{ mydict | dict2items }}"
Ansible command : ansible-playbook -vv -i localhost, localvars.yml
Expected results :
Getting mydict.fooX.params.barX.alias dynamically for each "barX" params in "fooX"
Getting mydict.fooX.dest dynamically for each "fooX"
Thank you for your help
I tried this :
- name: Using dict2items
ansible.builtin.debug:
msg: |-
"item.key = {{ item.key }}
item.value = {{ item.value }}"
loop: "{{ mydict | dict2items }}"
Which is working fine to get all values in mydict like mydict.foo1.dest, but i'm struggling to get all params values
Thanks for your help