# Executing blocks after failed

**URL:** <https://forum.ansible.com/t/executing-blocks-after-failed/20617>\
**Category:** Ansible Developer\
**Created:** [February 18, 2016, 4:10pm UTC](https://forum.ansible.com/t/executing-blocks-after-failed/20617 "2016-02-18T16:10:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [February 18, 2016, 4:10pm UTC](https://forum.ansible.com/t/executing-blocks-after-failed/20617/1 "2016-02-18T16:10:55Z")

</div>

Hi,

I am not sure if this is the expected behaviour or it is a bug (I don’t even know if it happens to everybody), so before opening an issue I ask here.

In a playbook like this:

> - name: myname  
> hosts: all  
> gather\_facts: True  
> tasks:
> - block:
> - file: path=/tmp/file1 state=directory
> - file: path=/tmp/file3 state=directory
> - file: path=/tmp/file30 state=directory  
> rescue:
> - file: path=/tmp/file2 state=directory  
> any\_errors\_fatal: yes

If “/tmp/file1” creation fails, it will jump to the “file2” creation, not executing the creation of “file3” nor the one of “file30”.  
This is how I would expect it to work, and it does.

Now. In a playbook like this:

> - name: myname  
> hosts: all  
> gather\_facts: True  
> tasks:
> - block:
> - block:
> - file: path=/tmp/file1 state=directory
> - file: path=/tmp/file3 state=directory
> - file: path=/tmp/file30 state=directory  
> rescue:
> - file: path=/tmp/file2 state=directory  
> any\_errors\_fatal: yes
> - block:
> - file: path=/tmp/file10 state=directory  
> rescue:
> - file: path=/tmp/file20 state=directory  
> any\_errors\_fatal: yes  
> rescue:
> - debug: msg=“FAILED”

I would expect the same. So, if “file1” creation fails, neither “file3” nor “file30” are created. “file2” is created,… nice. BUT! “file10” is also created, so, the second block is executed and I would expect that it would not.

Do someone knows id it may be a bug and I should open an issue or if it is expected?

Thanks!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 18, 2016, 4:34pm UTC](https://forum.ansible.com/t/executing-blocks-after-failed/20617/2 "2016-02-18T16:34:32Z")

</div>

i would expect file 10 to be created unless file2 fails, as block/rescue ‘resets’ the errors to the result of the rescue block.

---

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [February 18, 2016, 4:49pm UTC](https://forum.ansible.com/t/executing-blocks-after-failed/20617/3 "2016-02-18T16:49:38Z")

</div>

Thanks Brian,

This is exactly what is happening. I just understood the concept wrong!
