Symptom:
There are some cases the SHELL scripts we run via ansible, the return code (rc) is not 0And it is expected to return non-zero.
Ansible always output stderr for you which can be annoyed. ie
TASK [run the script to get the result] ************************************************************************************************
fatal: [acmsdbv3053.us.oracle.com]: FAILED! => {"changed": true, "cmd": ". /tmp/spectre-meltdown-checker-ansible.sh --batch text", "delta": "0:00:01.688319", "end": "2018-03-19 00:36:12.670522", "failed": true, "msg": "non-zero return code", "rc": 2, "start": "2018-03-19 00:36:10.982203", "stderr":
We try to hide them
Solution:
Use ignore_errors to continue the ansible yml file without disruption by the failed errorUse failed_when to be set as false. It will force the task never to be failed
Example codes like
- name: run the script to get the result
shell: |
. /tmp/spectre-meltdown-checker-ansible.sh --batch text
register: output
failed_when: false
ignore_errors: True
Before set failed_when
"changed": true,
"cmd": ". /tmp/spectre-meltdown-checker-ansible.sh --batch text",
"delta": "0:00:01.724031",
"end": "2018-03-19 00:55:37.677224",
"failed": true
After set failed_when
"changed": true,
"cmd": ". /tmp/spectre-meltdown-checker-ansible.sh --batch text",
"delta": "0:00:01.966887",
"end": "2018-03-19 00:53:10.673414",
"failed": false,
"failed_when_result": false,
No comments:
Post a Comment