# ansible block not running as expected

**URL:** <https://forum.ansible.com/t/ansible-block-not-running-as-expected/23736>\
**Category:** Ansible Project\
**Created:** [February 15, 2017, 6:51am UTC](https://forum.ansible.com/t/ansible-block-not-running-as-expected/23736 "2017-02-15T06:51:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_Paraschiv](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Adrian\_Paraschiv](https://forum.ansible.com/u/Adrian_Paraschiv)\
**Post date:** [February 15, 2017, 6:51am UTC](https://forum.ansible.com/t/ansible-block-not-running-as-expected/23736/1 "2017-02-15T06:51:37Z")

</div>

I have ansible 2.2.1.0 and I have this role:

```auto
- block:
    - shell: echo 1
    - shell: fail
    - shell: echo 2
  rescue:
    - shell: echo 3
  always:
    - shell: echo 4

- name: running something after the block
  shell: echo 5
 

```

If I run this role, the first part of the block fails because of the “fail” command (which does not exist 🙂 “stderr: /bin/sh: 1: fail: not found”) so the rescue kicks + always. But the last task, the one “running something after the block” never runs. The play finises!

Why is that ? The expected result I would see it as: if the first part of the block fails rescue kicks in + always (if any) and then continues the play run with the rest of the tasks.

In the documentation there is nothing about this.

Is there a workaround this ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 15, 2017, 9:25am UTC](https://forum.ansible.com/t/ansible-block-not-running-as-expected/23736/2 "2017-02-15T09:25:19Z")

</div>

I can't confirm this with 2.2.1.0

---

<div class="post-metadata">

**Author:** ![Adrian\_Paraschiv](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Adrian\_Paraschiv](https://forum.ansible.com/u/Adrian_Paraschiv)\
**Post date:** [February 15, 2017, 9:28am UTC](https://forum.ansible.com/t/ansible-block-not-running-as-expected/23736/3 "2017-02-15T09:28:00Z")

</div>

Because I said it’s a role and you put them as tasks 😉

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 15, 2017, 10:00am UTC](https://forum.ansible.com/t/ansible-block-not-running-as-expected/23736/4 "2017-02-15T10:00:30Z")

</div>

Sorry about that, I didn't think it would matter, but it does.  
Testet the tasks in a role and it stopped as you say.

Testet Ansible 2.1.4.0 and 2.2.0.0 and there it works as expected, so this bug/behaviour was introduced in 2.2.1.0.

---

<div class="post-metadata">

**Author:** ![John\_Dhom](https://avatars.discourse-cdn.com/v4/letter/j/8dc957/32.png) [@John\_Dhom](https://forum.ansible.com/u/John_Dhom)\
**Post date:** [February 15, 2017, 7:44pm UTC](https://forum.ansible.com/t/ansible-block-not-running-as-expected/23736/5 "2017-02-15T19:44:45Z")

</div>

That is correct. We ran into this last week as well. Found the bug here… [https://github.com/ansible/ansible/issues/20736](https://github.com/ansible/ansible/issues/20736)

Best,  
/jhd

---

<div class="post-metadata">

**Author:** ![Kevin\_Carter](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@Kevin\_Carter](https://forum.ansible.com/u/Kevin_Carter)\
**Post date:** [June 16, 2017, 2:41am UTC](https://forum.ansible.com/t/ansible-block-not-running-as-expected/23736/6 "2017-06-16T02:41:04Z")

</div>

++ Just we began running 2.2.3.0 and we’re seeing this same behavior.
