Grouping tasks with blocks
---
- name: Attempt and Graceful Rollback Demo
hosts: all
tasks:
- name: Print a message
ansible.builtin.debug:
msg: 'I execute normally'
# This task prints a message indicating normal execution.
- name: Force a failure
ansible.builtin.command: /bin/false
# This task intentionally fails by executing a non-existent command.
- name: Never print this
ansible.builtin.debug:
msg: 'I never execute, due to the above task failing, :-('
# This task will not execute because the previous task failed.
rescue:
- name: Print when errors
ansible.builtin.debug:
msg: 'I caught an error'
# In case of an error, this task prints a message.
- name: Force a failure in middle of recovery! >:-)
ansible.builtin.command: /bin/false
# This task intentionally fails during the recovery phase.
- name: Never print this
ansible.builtin.debug:
msg: 'I also never execute :-('
# This task will not execute due to the previous task failing.
always:
- name: Always do this
ansible.builtin.debug:
msg: "This always executes"
# Regardless of success or failure, this task always runs.Last updated