I’m trying to prepare a list of dicts with all needed data received from JSON file. I already parsed the file and it looks good but I still need to:
-
Add new element to every dict in the list “package: item” where item is get from the with_items: “{{ packages_to_import }}”. This variable is a simple list with all files I need to process.
-
Is there any way to also filter this list (in the same task) and remove all dicts where on of the keys has null value? I can add condition do the next task but then there is a lot of skipped items and it makes the output less readable.
my task:
- name: "Read JSON files"
set_fact:
json_content: "{{ json_content |
default([]) + ((lookup('file', item) |
from_json ).transferDetails |
json_query('[].{name: transferObject.summary.name, id: transferObject.summary.id, path: transferObject.contentSourceLocation}') |
list }}"
with_items: "{{ packages_to_import }}"
Current dict that I manged to create:
ok: [localhost] => {
"msg": [
{
"id": "123456789",
"name": "filename1",
"path": null
},
{
"id": "1234567",
"name": "filename2",
"path": "/folder1/folder2"
},
{
"id": "1234567",
"name": "filename3",
"path": "folder1"
}
}
I would like to achivie:
ok: [localhost] => {
"msg": [
{
"id": "1234567",
"name": "filename2",
"path": "/folder1/folder2",
"package: "/folder1/folder2/file2
},
{
"id": "1234567",
"name": "filename3",
"path": "folder1",
"package: "/folder1/file3
}
}