Rescue block doesn't seem to work when error is in an included file

So i was hoping to use blocks as an easy way to notify success/failure of ansible runs.

  • block:

  • include: build.yml

  • include: deploy_site.yml

  • name: Notify Slack it successfully deployed
    slack:

  • rescue:

  • name: Notify Slack it failed
    slack:

When there is an error in ether of the included yml files. Rescue never seems to be executed.

This is running the latest devel.

This is a bug, open a github issue please, using this template https://raw.githubusercontent.com/ansible/ansible/devel/ISSUE_TEMPLATE.md and supplying a minimal reproducible test will help us getting this fixed.

Hi Frank, I did just test this out on the latest version of devel, and it appears to be working for me just fine:

cat fail.yml

  • fail:

cat test.yml

  • hosts: localhost
    gather_facts: no
    tasks:
  • block:
  • include: fail.yml
  • debug: msg=“you should not see me”
    rescue:
  • debug: msg=“here we are in the rescue”
    always:
  • debug: msg=“here we are in the always”

TASK [include] *****************************************************************
included: fail.yml for localhost

TASK [fail] ********************************************************************
fatal: [localhost]: FAILED! => {“changed”: false, “failed”: true, “msg”: “Failed as requested from task”}

TASK [debug msg=here we are in the rescue] *************************************
ok: [localhost] => {
“changed”: false,
“msg”: “here we are in the rescue”
}

TASK [debug msg=here we are in the always] *************************************
ok: [localhost] => {
“changed”: false,
“msg”: “here we are in the always”
}

Can you test against the latest pull from devel (if you’re not already), and share more information about what the include failures may involve?

I am dumb, and the issue is because i have:

`

  • rescue

`

when it should be:

rescue

My mistake.

he, no worries, I didn't catch that either