Add example task succeeding when RC is non-zero (#23698)

* Add example task succeeding when RC is non-zero

I added an example on how to use the return code to decide yourself
what is considered a failure.

This might have helped for #23679.

* Use diff as example command, instead of robocopy
This commit is contained in:
Dag Wieers 2017-04-18 15:17:52 +01:00 committed by John R Barker
parent fdce6484ec
commit d188f56535

View file

@ -75,11 +75,18 @@ if the string "FAILED" is in the output.
Ansible in 1.4 and later provides a way to specify this behavior as follows::
- name: this command prints FAILED when it fails
- name: Fail task when the command error output prints FAILED
command: /usr/bin/example-command -x -y -z
register: command_result
failed_when: "'FAILED' in command_result.stderr"
or based on the return code::
- name: Fail task when both files are identical
raw: diff foo/file1 bar/file2
register: diff_cmd
failed_when: diff_cmd.rc == 0 or diff_cmd.rc >= 2
In previous version of Ansible, this can be still be accomplished as follows::
- name: this command prints FAILED when it fails