Hi everyone,
I try to understand ansible dictionaries and for my need I use lists in a
dictionary which makes the code not simple and I am struggling to
understand that:
Below there're part of my playbook and result:
user_list:
- name: "name1"
city: "New York"
phone: "03-45-67"
- name: "name2"
city: "London"
phone: "04-45-67"
- name: "name3"
city: "Berlin"
phone: "05-45-67"
I need to retrieve information like each phone number for each name and I
found this solution:
- name: debugging dict
debug:
msg:
- "type of user_list: {{ user_list | type_debug }}"
- " this {{ item['name'] }} is relation to this phone : {{
item['phone'] }}"
loop: "{{ user_list }}"
and here's the result:
TASK [ansible_dict_test : debugging dict]
*************************************************************************************************
ok: [localhost] => (item={'name': 'name1', 'city': 'New York', 'phone':
'03-45-67'}) => {
"msg": [
"type of user_list: list",
" this name1 is relation to this phone : 03-45-67"
]
}
ok: [localhost] => (item={'name': 'name2', 'city': 'London', 'phone':
'04-45-67'}) => {
"msg": [
"type of user_list: list",
" this name2 is relation to this phone : 04-45-67"
]
}
ok: [localhost] => (item={'name': 'name3', 'city': 'Berlin', 'phone':
'05-45-67'}) => {
"msg": [
"type of user_list: list",
" this name3 is relation to this phone : 05-45-67"
]
}
I've some question about that:
1) type_debug read from user_list and it is a dict then why it give a list
as result?
2) I has understood, user_list ist the key of dict and the rest is the
value. In that case why item['name'] is like a key?
3) Is my playbook good or is a better solution?
Thank you in advance for your help because I am really trying to understand
in detail how dictionaries work and I need your advice.
Best regards, H
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2e3e7529-6b09-46c0-a1d2-38bce7d74501n%40googlegroups.com.