cancel
Showing results for 
Search instead for 
Did you mean: 
Ravi_Shanker
Flight Engineer
Flight Engineer
  • 1,176 Views

Chapter 7 slide 5 do374-2.2

Jump to solution

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. 

Certification ID: 111-010-393
Labels (1)
1 Solution

Accepted Solutions
Chetan_Tiwary_
Community Manager
Community Manager
  • 1,145 Views

Hello @Ravi_Shanker !

Thanks for reaching out!

Please go to ch07s06 and refer the guided exercise ( step 1.3) :

If I use this :

Chetan_Tiwary__0-1695232013156.png

It works as expected : see the invocation 

Chetan_Tiwary__1-1695232084288.png

whereas if I do like this :

Chetan_Tiwary__2-1695232132219.png

I get an error : 

Chetan_Tiwary__3-1695232170139.png

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.

View solution in original post

5 Replies
laurpaum
Flight Engineer
Flight Engineer
  • 1,147 Views

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.

Chetan_Tiwary_
Community Manager
Community Manager
  • 1,146 Views

Hello @Ravi_Shanker !

Thanks for reaching out!

Please go to ch07s06 and refer the guided exercise ( step 1.3) :

If I use this :

Chetan_Tiwary__0-1695232013156.png

It works as expected : see the invocation 

Chetan_Tiwary__1-1695232084288.png

whereas if I do like this :

Chetan_Tiwary__2-1695232132219.png

I get an error : 

Chetan_Tiwary__3-1695232170139.png

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.

laurpaum
Flight Engineer
Flight Engineer
  • 1,142 Views

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'] }}.

 

Chetan_Tiwary_
Community Manager
Community Manager
  • 1,141 Views

Ah! thanks for that. Corrected the typo.

Ravi_Shanker
Flight Engineer
Flight Engineer
  • 1,124 Views

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 . 

Certification ID: 111-010-393
Join the discussion
You must log in to join this conversation.