In the video for ch07 s05 the groups variable is written as "{{ item['value']['groups'] }}".
https://rol.redhat.com/rol/app/courses/do374-2.2/pages/ch07s05
I am confused as to why value comes before groups.
Should it not be "{{ item['groups']['value'] }}" ?
If anyone can throw some more information on this would be helpful for my understanding.
Hello @Ravi_Shanker !
Thanks for reaching out!
Please go to ch07s06 and refer the guided exercise ( step 1.3) :
If I use this :
It works as expected : see the invocation
whereas if I do like this :
I get an error :
The crux is - The correct way to access the groups value in the item is {{ item['value']['groups'] }}. The item['value'] key will return the entire value of the item, which is a dictionary. The structure we have defined in our dictionary follows this pattern, with 'value' as the key to access the sub-dictionary and 'gid' as a subkey to retrieve the GID.
The dict lookup plugin takes a dictionary as input and returns a list where each item is a dictionary having a 'key' and 'value' keys that correspond to the keys and values of the original dictionary.
Using the myusers variable from the video as input, the first iteration would have following item :
item:
key: fred
value:
groups:
- flintstones
- wheel
password: yabadabadoo
The groups can be accessed in item['value']['groups'], as stated in the video.
Hello @Ravi_Shanker !
Thanks for reaching out!
Please go to ch07s06 and refer the guided exercise ( step 1.3) :
If I use this :
It works as expected : see the invocation
whereas if I do like this :
I get an error :
The crux is - The correct way to access the groups value in the item is {{ item['value']['groups'] }}. The item['value'] key will return the entire value of the item, which is a dictionary. The structure we have defined in our dictionary follows this pattern, with 'value' as the key to access the sub-dictionary and 'gid' as a subkey to retrieve the GID.
There's a confusing typo in your answer.
The sentence at the end of the explanation and examples :
The correct way to access the groups value in the item is {{ item['groups']['value'] }}.
Should read :
The correct way to access the groups value in the item is {{ item['value']['groups'] }}.
Ah! thanks for that. Corrected the typo.
Thanks and appreciate your detailed explanation. It is going to take time for me to soak this. Coming from ansible_facts to dicts and loops seems a bit of a challenge for me. I wish for more examples and explanations on this topic. Find this chapter hardest in do374 .
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.