I have been struggled with Ansible for a time and finally requesting for any help if possible,
Having a set of Nifi policies:
"nifi_raw_policies": [
{
"action": "read",
"group": "8c052e6c-0184-1000-0000-000072a0bb44",
"resource": "/data/process-groups/8b6b5c9f-0184-1000-57e3-f27fc56dd4aa"
},
{
"action": "read",
"group": "8c0536d8-0184-1000-0000-000018ba98a9",
"resource": "/data/process-groups/8b6b5c9f-0184-1000-57e3-f27fc56dd4aa"
}
]
I have the need to group them to obtain:
"nifi_grouped_policies": [
{
"policy": "read/data/process-groups/8b6b5c9f-0184-1000-57e3-f27fc56dd4aa",
"groups": [ "8c052e6c-0184-1000-0000-000072a0bb44","8c0536d8-0184-1000-0000-000018ba98a9" ]
}
]
But until now I'm still unable to group by "action"+"resource" key getting a list of related "group" in a new field "groups". I have managed to obtain only a list of dictionaries in the form { "action"+"resource" : "group1" }, ..., { "action"+"resource" : "groupN" }
Related ansible task code:
- name: Declare policies (simplest)
set_fact:
nifi_raw_policies: [
{
"action": "read",
"group": "8c052e6c-0184-1000-0000-000072a0bb44",
"resource": "/data/process-groups/8b6b5c9f-0184-1000-57e3-f27fc56dd4aa"
},
{
"action": "read",
"group": "8c0536d8-0184-1000-0000-000018ba98a9",
"resource": "/data/process-groups/8b6b5c9f-0184-1000-57e3-f27fc56dd4aa"
}
]
- name: Declare policies - debug
debug: var=nifi_raw_policies
- name: Combine action and resource
set_fact:
nifi_policies: >-
{{ nifi_policies|default([])
| union([{
item.action + item.resource : item.group
}])
}}
with_items: "{{ nifi_raw_policies }}"
- name: Combine action and resource - debug
debug: var=nifi_policies
After several tries using combine, union, groupby ansible filters without success.. any insigth would be highly appreciated.
Best regards,