我需要判断下面的JSON文件中是否有0
以外的退出代码.
{
"domains": {
"app1": {
"status": "Running"
},
"app2": {
"status": "Terminated",
"exit code": 2
},
"app3": {
"status": "Running"
},
"app4": {
"status": "Running"
},
"app5": {
"status": "Terminated",
"exit code": 0
}
}
}
找到0
以外的退出代码后,我希望Ansible任务失败.我try 了以下代码:
- 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) }}"
但是,这似乎不起作用.