I need to check if there are exit codes other than 0
in the JSON file below.
{
"domains": {
"app1": {
"status": "Running"
},
"app2": {
"status": "Terminated",
"exit code": 2
},
"app3": {
"status": "Running"
},
"app4": {
"status": "Running"
},
"app5": {
"status": "Terminated",
"exit code": 0
}
}
}
Upon finding exit code other than 0
, I want the Ansible task to fail. I tried the following code:
- name: Execute command to obtain json list.
command: cat test.json
register: result
- name: save the Json data to a Variable as a Fact
set_fact:
jsondata: "{{ result.stdout | from_json }}"
- name: Find string
when: jsondata.stdout is search('Terminated')
debug:
msg: "{{ jsondata.stdout }}"
failed_when: "{{ jsondata.stdout | jsonquery(domains.*[exit code] != 0) }}"
But, this does not seem to work.