Using the rescue section
The rescue section of a block defines a logical unit of tasks that will be executed should an actual failure be encountered within a block. As Ansible performs the tasks within a block, from top to bottom, when an actual failure is encountered, execution will jump to the first task of the rescue section of the block if it exists. Then, tasks are performed from top to bottom until either the end of the rescue section is reached, or another error is encountered.
After the rescue section completes, task execution continues with whatever comes after the block, as if there were no errors. This provides a way to gracefully handle errors, allowing cleanup tasks to be defined so that a system is not left in a completely broken ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access