Created
November 13, 2020 17:44
-
-
Save richm/25cef183fae583e15ff871f2d500ab57 to your computer and use it in GitHub Desktop.
nested block with error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: test nested blocks | |
hosts: localhost | |
tasks: | |
- block: | |
- name: first outer level task | |
debug: | |
msg: first outer level task | |
- block: | |
- name: first inner level task | |
debug: | |
msg: first inner level task | |
- name: inner task that fails | |
fail: | |
msg: inner task that fails | |
- name: inner task that should never execute | |
debug: | |
msg: inner task that should never execute | |
always: | |
- name: first inner block always task | |
debug: | |
msg: first inner block always task ansible_failed_result is {{ ansible_failed_result | d("undefined") | to_nice_json }} | |
- block: | |
- name: second block inner level task | |
debug: | |
msg: second block inner level task | |
- name: second outer level task | |
debug: | |
msg: second outer level task | |
rescue: | |
- name: outer block rescue task | |
debug: | |
msg: outer block rescue task ansible_failed_result is {{ ansible_failed_result | d("undefined") | to_nice_json }} | |
the output looks like this: | |
TASK [inner task that fails] *************************************************** | |
task path: /home/rmeggins/ansible_sandbox/nested-block.yml:13 | |
fatal: [localhost]: FAILED! => { | |
"changed": false | |
} | |
MSG: | |
inner task that fails | |
TASK [first inner block always task] ******************************************* | |
task path: /home/rmeggins/ansible_sandbox/nested-block.yml:20 | |
ok: [localhost] => {} | |
MSG: | |
first inner block always task ansible_failed_result is "undefined" | |
TASK [outer block rescue task] ************************************************* | |
task path: /home/rmeggins/ansible_sandbox/nested-block.yml:31 | |
ok: [localhost] => {} | |
MSG: | |
outer block rescue task ansible_failed_result is "undefined" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment