create a dict from a list (value of another dict)

Hi Team,

My playbook role receive a dict coming from a lookup file, linux_file_list is the variable name of this lookup. This dict has only one key and some lists as value. Elements of these lists are dict too.

Here’s my debug to see the content:

  • Name: debugging
    debug:
    msg:“{{ linux_file_list | dict2items }}”

And here’s the result (a part…):

TASK [reposync : debugging] *******************************************************************************************************************************************************

ok: => {

“msg”: [

[

{

“key”: “list_of_linux”,

“value”: [

{

“description”: “linux SLES”,

“enabled”: 1,

“version”: 15,

“name”: “sles”

},

{

“description”: “linux RHEL”,

“enabled”: 1,

“version”: 8.4,

“name”: “rhel”

}

]

}

]

]

}

Now, I want to define the name value as a dict to loop on this to have at the end a loop to retrieve these variables, like so…

“name: {{ item[‘name’] }}”
“description: {{ item[‘description’] }}”
“version: {{ item[‘version’] }}”
etc…

Unfortunately I don’t find how can i do that. I’ve try many things, like item.value[0][0] to have the first element of the first list but it doesn’t run.

With set_fact i cannot do a dict on the list too:

  • set_fact:
    dict: “{{ dict(_keys|zip(linux_file_list)) }}"
    vars:
    _keys: “{{ item[‘value’]|map(attribute=‘name’)|list }}”
    loop: “{{ linux_file_list | dict2items }}”

As anyone an Idea how can I resolve this? I can’t see my problem clearly anymore and I need your help

Thanks in advance for your help, H

try the subelement filter

I’ve try some subelements but cannot retrieve the right data.

I've try some subelements but cannot retrieve the right data.
ie

I don't get why you use the dict2items filter on a list of dicts. You can start producing output from the "linux_file_list" variable directly.

Regards
         Racke