# Block & rescue misconception

**URL:** <https://forum.ansible.com/t/block-rescue-misconception/29548>\
**Category:** Ansible Project\
**Created:** [January 28, 2019, 4:52pm UTC](https://forum.ansible.com/t/block-rescue-misconception/29548 "2019-01-28T16:52:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergio.fernandez](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@sergio.fernandez](https://forum.ansible.com/u/sergio.fernandez)\
**Post date:** [January 28, 2019, 4:52pm UTC](https://forum.ansible.com/t/block-rescue-misconception/29548/1 "2019-01-28T16:52:59Z")

</div>

Hi all,

I’m using Ansible 2.5.11, using the EC2 dynamic inventory script. I’m trying to do some tasks over an instance with a role using block and rescue, so if one of the tasks fails, the rescue task runs (removing the instance). But I don’t know why the rescue tasks never runs.

I’m running a playbook which executes the roles, like this:  
`

# Install common packages and tasks, and deploy software

- hosts: tag\_Environment\_Development:&tag\_Role\_Pilot:&tag\_Name\_Backend  
gather\_facts: True  
vars\_files:
- variables-dev.yml  
roles:
- deploy-api  
`

And the role deploy-api/tasks/main.yml looks like 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:** [January 28, 2019, 5:19pm UTC](https://forum.ansible.com/t/block-rescue-misconception/29548/2 "2019-01-28T17:19:16Z")

</div>

Your syntax is wrong, rescue should not have a dash, check the documentation for correct syntax  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_blocks.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html)

---

<div class="post-metadata">

**Author:** ![sergio.fernandez](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@sergio.fernandez](https://forum.ansible.com/u/sergio.fernandez)\
**Post date:** [January 29, 2019, 11:51am UTC](https://forum.ansible.com/t/block-rescue-misconception/29548/3 "2019-01-29T11:51:09Z")

</div>

HI,

Si as far as I understand, and my tests points to int, a block & rescue is needed for every task in a role? Is not applicable to various tasks?

Regards.

---

<div class="post-metadata">

**Author:** ![sergio.fernandez](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@sergio.fernandez](https://forum.ansible.com/u/sergio.fernandez)\
**Post date:** [January 29, 2019, 2:57pm UTC](https://forum.ansible.com/t/block-rescue-misconception/29548/4 "2019-01-29T14:57:27Z")

</div>

Hi all,

For the record, as I think this is not specifically documented in the official documentation:

When using block inside a role, the correct syntax is:
