You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve failed_when documentation and fix minor errors (#3249)
* Improve failed_when documentation and fix minor errors
- Add clarifying example for 'or' operator in failed_when conditions
- Fix template syntax: remove extra space in Jinja2 braces
Signed-off-by: Piyush Malik <[email protected]>
* Update docs/docsite/rst/playbook_guide/playbooks_error_handling.rst
Co-authored-by: Felix Fontein <[email protected]>
---------
Signed-off-by: Piyush Malik <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
Copy file name to clipboardExpand all lines: docs/docsite/rst/playbook_guide/playbooks_error_handling.rst
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,8 +61,7 @@ And at the playbook level:
61
61
Resetting unreachable hosts
62
62
===========================
63
63
64
-
If Ansible cannot connect to a host, it marks that host as 'UNREACHABLE' and removes it from the list of active hosts for the run. You can use `meta: clear_host_errors` to reactivate all hosts, so subsequent tasks can try to reach them again.
65
-
64
+
If Ansible cannot connect to a host, it marks that host as 'UNREACHABLE' and removes it from the list of active hosts for the run. You can use ``meta: clear_host_errors`` to reactivate all hosts, so subsequent tasks can try to reach them again.
66
65
67
66
.. _handlers_and_failure:
68
67
@@ -87,7 +86,16 @@ the handler from running, such as a host becoming unreachable.)
87
86
Defining failure
88
87
================
89
88
90
-
Ansible lets you define what "failure" means in each task using the ``failed_when`` conditional. As with all conditionals in Ansible, lists of multiple ``failed_when`` conditions are joined with an implicit ``and``, meaning the task only fails when *all* conditions are met. If you want to trigger a failure when any of the conditions is met, you must define the conditions in a string with an explicit ``or`` operator.
89
+
Ansible lets you define what "failure" means in each task using the ``failed_when`` conditional. As with all conditionals in Ansible, lists of multiple ``failed_when`` conditions are joined with an implicit ``and``, meaning the task only fails when *all* conditions are met. If you want to trigger a failure when *any* of the conditions is met, you must define the conditions in a single string with an explicit ``or`` operator.
90
+
91
+
For example, to fail when either of two conditions is true:
92
+
93
+
.. code-block:: yaml
94
+
95
+
- name: Fail task when either condition is met
96
+
ansible.builtin.command: /usr/bin/example-command
97
+
register: command_result
98
+
failed_when: command_result.rc != 0 or 'ERROR' in command_result.stdout
91
99
92
100
You may check for failure by searching for a word or phrase in the output of a command
93
101
@@ -184,7 +192,7 @@ You can reference simple variables in conditionals to avoid repeating certain te
0 commit comments