I have the below json where i want to extract each subset of rules based on the name (example: (SUP) Filesystem usage /var >85%) in my ansible playbook so i can use it as input for my following task.
{"nprd_infrastructure_disk_rules": [
[
{
"schemaId": "builtin:anomaly-detection.disk-rules",
"externalId": "string",
"scope": "environment",
"value": {
"name": "(SUP) Filesystem usage /var >85%",
"enabled": true,
"metric": "LOW_DISK_SPACE",
"thresholdPercent": 15,
"sampleLimit": {
"violatingSamples": 3,
"samples": 3
},
"diskNameFilter": {
"operator": "EQUALS",
"value": "/var"
},
"tagFilters": [
"Environment:sup",
"Area:IT"
]
}
}
],
[
{
"schemaId": "builtin:anomaly-detection.disk-rules",
"externalId": "string",
"scope": "environment",
"value": {
"name": "(SUP) Filesystem usage /var >95%",
"enabled": true,
"metric": "LOW_DISK_SPACE",
"thresholdPercent": 5,
"sampleLimit": {
"violatingSamples": 3,
"samples": 3
},
"diskNameFilter": {
"operator": "EQUALS",
"value": "/var"
},
"tagFilters": [
"Environment:sup",
"Area:IT"
]
}
}
]
]
}
The closest attempt was the below code:
set_fact:
body_nprd: "{{ nprd_infrastructure_disk_rules | json_query(querystr) }}"
vars:
querystr: '[][value][?name == to_string(`Filesystem usage /var >95% (SUP)`)]'
This gave me the below output where i am missing some fields.
[
{
"name": "Filesystem usage /var >95% (SUP)",
"enabled": true,
"metric": "LOW_DISK_SPACE",
"thresholdPercent": 5,
"sampleLimit": {
"violatingSamples": 3,
"samples": 3
},
"diskNameFilter": {
"operator": "EQUALS",
"value": "/var"
},
"tagFilters": [
"Environment:sup",
"Area:IT"
]
}
]
What i want to achieve and get is:
[
{
"schemaId": "builtin:anomaly-detection.disk-rules",
"externalId": "string",
"scope": "environment",
"value": {
"name": "(SUP) Filesystem usage /var >95%",
"enabled": true,
"metric": "LOW_DISK_SPACE",
"thresholdPercent": 5,
"sampleLimit": {
"violatingSamples": 3,
"samples": 3
},
"diskNameFilter": {
"operator": "EQUALS",
"value": "/var"
},
"tagFilters": [
"Environment:sup",
"Area:IT"
]
}
}
]