1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Update changed_when and failed_when examples (#50411)

Added examples in playbooks_error_handling doc for handlining
multiple conditions in changed_when and failed_when

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2019-01-03 20:20:59 +05:30 committed by Sandra McCann
parent 0a56a22098
commit a45063defe
2 changed files with 20 additions and 0 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- Add examples in documentation to explain how to handle multiple conditions in changed_when and failed_when.

View file

@ -93,6 +93,15 @@ In previous version of Ansible, this can still be accomplished as follows::
msg: "the command failed"
when: "'FAILED' in command_result.stderr"
You can also combine multiple conditions to specify this behavior as follows::
- name: Check if a file exists in temp and fail task if it does
command: ls /tmp/this_should_not_be_here
register: result
failed_when:
- '"No such" not in result.stdout'
- result.rc == 0
.. _override_the_changed_result:
Overriding The Changed Result
@ -116,6 +125,15 @@ does not cause handlers to fire::
- shell: wall 'beep'
changed_when: False
You can also combine multiple conditions to override "changed" result::
- command: /bin/fake_command
register: result
ignore_errors: True
changed_when:
- '"ERROR" in result.stderr'
- result.rc == 2
Aborting the play
`````````````````