Hi!
When I use Block that has a task that fails, and then I rescue it, what should be the ansible exit code? AFAIK, on the documentation, there is no information about it.
I have a scenario where I would like to use rescue with the “rollback” tasks, and then would like Ansible to return an exit code != 0, but with the “rescue block”, I got always 0.
Example playbook:
- hosts: localhost
gather_facts: False
tasks:
- block:
- fail: msg="fail"
rescue:
- debug: msg="rescue"
always:
- debug: msg="always"
PLAY RECAP **********************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=1
When we run this simple playbook and then do “echo $?” I got 0 instead of != 0
If there are failed tasks (and they aren’t ignored) I would expect a failed playbook…
Am I thinking right? What is your opinion?
PS: I open an issue giving some ideas for feature flag on the block: https://github.com/ansible/ansible/issues/26595