# Block/Rescue/Always Exit Code

**URL:** <https://forum.ansible.com/t/block-rescue-always-exit-code/24947>\
**Category:** Ansible Project\
**Created:** [July 10, 2017, 9:29pm UTC](https://forum.ansible.com/t/block-rescue-always-exit-code/24947 "2017-07-10T21:29:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joao\_Cravo](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Joao\_Cravo](https://forum.ansible.com/u/Joao_Cravo)\
**Post date:** [July 10, 2017, 9:29pm UTC](https://forum.ansible.com/t/block-rescue-always-exit-code/24947/1 "2017-07-10T21:29:45Z")

</div>

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:

```auto
- hosts: localhost
  gather_facts: False

  tasks:
    - block:
        - fail: msg="fail"
      rescue:
        - debug: msg="rescue"
      always:
        - debug: msg="always"

```

```auto

```

```auto
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](https://github.com/ansible/ansible/issues/26595)
