I have a JSON file with some data on it, like the below one:
{
"84d0da32-c945-9844-86cc-4b4bd6100dc5": {
"UUID": "84d0da32-c945-9844-86cc-4b4bd6100dc5",
"GroupName": "TEST1",
"EntryTitle": "host1",
"Username": "sys",
"NewPassword": "@PVmkiajauauajjhfz-5/NN"
},
"test": {
"UUID": "5c3c162f-0a80-f949-85a0-afcf9aedb6c8",
"GroupName": "TEST2",
"EntryTitle": "host2",
"Username": "sys",
"NewPassword": "H7-uPz2mkaaua@ki7q?NSs?"
}
}
I am trying to filter only the field GroupName
or EntryTitle
, with json_query
but it always give null
, if I try to write all GroupName
field, it returns both.
I only want to pass for example if GroupName
is TEST2
return the EntryTitle
field.
Example of my code until now:
- name: load json data
shell: cat entries.json
register: result
- name: save json do var
set_fact:
jsondata: "{{ result.stdout | from_json }}"
- name: server name
set_fact:
servername: "{{ jsondata | json_query(jq) }}"
vars:
jq: "*.GroupName"
- name: Print
debug:
msg: "{{ item }}"
with_items:
- "{{ servername }}"