ansible/docsite/latest/rst/playbooks_error_handling.rst

71 lines
2.1 KiB
ReStructuredText
Raw Normal View History

2013-09-30 01:10:28 +02:00
Error Handling In Playbooks
===========================
2012-05-13 17:00:02 +02:00
.. contents::
:depth: 2
2013-10-03 04:03:15 +02:00
Ansible normally has defaults that make sure to check the return codes of commands and modules and
it fails fast -- forcing an error to be dealt with unless you decide otherwise.
y
Sometimes a command that returns 0 isn't an error. Sometimes a command might not always
need to report that it 'changed' the remote system. This section describes how to change
the default behavior of Ansible for certain tasks so output and error handling behavior is
as desired.
.. _ignoring_failed_commands:
Ignoring Failed Commands
````````````````````````
2012-10-17 00:15:41 +02:00
.. versionadded:: 0.6
Generally playbooks will stop executing any more steps on a host that
has a failure. Sometimes, though, you want to continue on. To do so,
write a task that looks like this::
- name: this will not be counted as a failure
2013-07-15 19:50:48 +02:00
command: /bin/false
ignore_errors: yes
.. _override_the_changed_result:
2013-09-30 01:10:28 +02:00
Overriding The Changed Result
`````````````````````````````
2013-07-14 21:43:10 +02:00
.. versionadded:: 1.3
2013-07-21 16:48:22 +02:00
When a shell/command or other module runs it will typically report
2013-07-24 00:49:27 +02:00
"changed" status based on whether it thinks it affected machine state.
2013-07-21 16:48:22 +02:00
Sometimes you will know, based on the return code
or output that it did not make any changes, and wish to override
the "changed" result such that it does not appear in report output or
does not cause handlers to fire::
2013-07-14 21:43:10 +02:00
tasks:
2013-07-21 16:48:22 +02:00
- shell: /usr/bin/billybass --mode="take me to the river"
register: bass_result
changed_when: "bass_result.rc != 2"
# this will never report 'changed' status
- shell: wall 'beep'
2013-07-14 21:43:10 +02:00
2012-05-13 17:00:02 +02:00
.. seealso::
:doc:`playbooks`
An introduction to playbooks
:doc:`playbooks_best_practices`
Best practices in playbooks
:doc:`playbooks_conditionals`
Conditional statements in playbooks
:doc:`playbooks_variables`
All about variables
`User Mailing List <http://groups.google.com/group/ansible-devel>`_
Have a question? Stop by the google group!
`irc.freenode.net <http://irc.freenode.net>`_
#ansible IRC chat channel
2012-05-13 17:00:02 +02:00