Am I mixing up things here?
As already mentioned in the comments, yes, it seems so. So you may proceed further with the there linked documentation and examples.
The following examples show how you could create a simple list of the first level of your dictionary kommunen
by using data manipulation and the Jinja 2 filter list
.
---
- hosts: localhost
become: false
gather_facts: false
vars:
kommunen:
weimar:
tld: stadt-weimar.de
desc: Kommune Weimar
admins:
fritzfriemel:
vorname: Fritz
name: Friemel
mail: f.friemel@stadt-weimar.de
frankfrokel:
vorname: Frank
name: Frokel
mail: f.frokel@stadt-weimar.de
erfurt:
admins:
tasks:
- name: "Account Daten testen"
debug:
msg: "{{ item }}"
loop: "{{ kommunen | list }}"
- name: Show admins
debug:
msg: "{{ kommunen[item].admins }}"
loop: "{{ kommunen | list }}"
resulting into an output of
TASK [Account Daten testen] **********
ok: [localhost] => (item=erfurt) =>
msg: erfurt
ok: [localhost] => (item=weimar) =>
msg: weimar
TASK [Show admins] *******************
ok: [localhost] => (item=erfurt) =>
msg: ''
ok: [localhost] => (item=weimar) =>
msg:
frankfrokel:
mail: f.frokel@stadt-weimar.de
name: Frokel
vorname: Frank
fritzfriemel:
mail: f.friemel@stadt-weimar.de
name: Friemel
vorname: Fritz
Documentation
Further Q&A
Is it mandatory to transfer the dict into a list, or can I point to an object directly?
This will depend on what you try to achieve. If you like to iterate over it, yes. If you have already some information from elsewhere you could use
- name: Set CITY
set_fact:
CITY: "weimar"
- name: Show admins
debug:
msg: "{{ kommunen[CITY].admins[item].name }}"
loop: "{{ kommunen[CITY].admins | list }}"
resulting into an output of
TASK [Set CITY] *************************
ok: [localhost]
TASK [Show admins] **********************
ok: [localhost] => (item=fritzfriemel) =>
msg: Friemel
ok: [localhost] => (item=frankfrokel) =>
msg: Frokel