Block & rescue misconception

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:

`

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

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.

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: