- name: Attempt and graceful roll back demo
block:
- ansible.builtin.debug:
msg: 'I execute normally'
- name: i force a failure
command: /bin/false
- ansible.builtin.debug:
msg: 'I never execute, due to the above task failing, :-('
rescue:
- ansible.builtin.debug:
msg: 'I caught an error'
- name: i force a failure in middle of recovery! >:-)
command: /bin/false
- ansible.builtin.debug:
msg: 'I also never execute :-('
always:
- ansible.builtin.debug:
msg: "This always executes"
ceuser@deyu:~/ansible_pb$ ansible-doc debug | grep ^EX -A4
EXAMPLES:
- name: Print the gateway for each host when defined
ansible.builtin.debug:
msg: System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}