From a45063defee738b2e37f70c3f572bfb049d727bd Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 3 Jan 2019 20:20:59 +0530 Subject: [PATCH] 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 --- .../fragments/change_failed_when_example.yaml | 2 ++ .../user_guide/playbooks_error_handling.rst | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 changelogs/fragments/change_failed_when_example.yaml diff --git a/changelogs/fragments/change_failed_when_example.yaml b/changelogs/fragments/change_failed_when_example.yaml new file mode 100644 index 00000000000..8dff5c9fee8 --- /dev/null +++ b/changelogs/fragments/change_failed_when_example.yaml @@ -0,0 +1,2 @@ +minor_changes: +- Add examples in documentation to explain how to handle multiple conditions in changed_when and failed_when. diff --git a/docs/docsite/rst/user_guide/playbooks_error_handling.rst b/docs/docsite/rst/user_guide/playbooks_error_handling.rst index fc2d53d8768..882dceb5d11 100644 --- a/docs/docsite/rst/user_guide/playbooks_error_handling.rst +++ b/docs/docsite/rst/user_guide/playbooks_error_handling.rst @@ -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 `````````````````