# efficient way to get email notification about failed task in a playbook or role

**URL:** <https://forum.ansible.com/t/efficient-way-to-get-email-notification-about-failed-task-in-a-playbook-or-role/28104>\
**Category:** Ansible Developer\
**Created:** [July 20, 2018, 7:01am UTC](https://forum.ansible.com/t/efficient-way-to-get-email-notification-about-failed-task-in-a-playbook-or-role/28104 "2018-07-20T07:01:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Panchal1](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@Sandeep\_Panchal1](https://forum.ansible.com/u/Sandeep_Panchal1)\
**Post date:** [July 20, 2018, 7:01am UTC](https://forum.ansible.com/t/efficient-way-to-get-email-notification-about-failed-task-in-a-playbook-or-role/28104/1 "2018-07-20T07:01:27Z")

</div>

Dear All,

is there any way to get failed task name captured in rescue section which can be email notified or submitted to slack system ?

looking for something which can be placed on “any\_variable\_for\_failed\_task” in below code.

- name: Check host accessibility  
hosts: localhost  
user: deploy  
gather\_facts: no  
tasks:
- block:
- command: echo OK 1
- command: echo OK 2
- command: echo OK 3
- command: echo OK 4
- command: echo OK 5
- command: echo OK 6
- command: ech OK 7
- command: echo OK 8
- command: echo OK 9
- command: echo OK 10  
rescue:
- name: send email when something goes wrong  
mail:  
host: localhost

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 20, 2018, 3:20pm UTC](https://forum.ansible.com/t/efficient-way-to-get-email-notification-about-failed-task-in-a-playbook-or-role/28104/2 "2018-07-20T15:20:29Z")

</div>

you should have 'ansible\_failed\_task' and 'ansible\_failed\_result'  
available for tasks in the rescue portion of a block

---

<div class="post-metadata">

**Author:** ![rbarlik](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@rbarlik](https://forum.ansible.com/u/rbarlik)\
**Post date:** [July 21, 2018, 10:18am UTC](https://forum.ansible.com/t/efficient-way-to-get-email-notification-about-failed-task-in-a-playbook-or-role/28104/3 "2018-07-21T10:18:57Z")

</div>

Thanks!

This is a really useful feature I didn’t know about.

After some digging I found the issue from a year ago: [https://github.com/ansible/ansible/issues/27970](https://github.com/ansible/ansible/issues/27970)

Looks like a time to finally document it.

Rastislav
