# How to detect a rescued task while using the CallbackBase?

**URL:** <https://forum.ansible.com/t/how-to-detect-a-rescued-task-while-using-the-callbackbase/36270>\
**Category:** Ansible Developer\
**Created:** [February 1, 2022, 5:27pm UTC](https://forum.ansible.com/t/how-to-detect-a-rescued-task-while-using-the-callbackbase/36270 "2022-02-01T17:27:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_Martinez](https://avatars.discourse-cdn.com/v4/letter/v/2acd7d/32.png) [@Victor\_Martinez](https://forum.ansible.com/u/Victor_Martinez)\
**Post date:** [February 1, 2022, 5:27pm UTC](https://forum.ansible.com/t/how-to-detect-a-rescued-task-while-using-the-callbackbase/36270/1 "2022-02-01T17:27:31Z")

</div>

Hi all,

I’d like to distinguish a failed task from a rescued time using a callback plugin, but I cannot see anything in [https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/\_\_init\_\_.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/ __init__.py)

Any hints how I can distinguish those two different status at the task level?

Thanks

---

<div class="post-metadata">

**Author:** ![Victor\_Martinez](https://avatars.discourse-cdn.com/v4/letter/v/2acd7d/32.png) [@Victor\_Martinez](https://forum.ansible.com/u/Victor_Martinez)\
**Post date:** [February 8, 2022, 7:24pm UTC](https://forum.ansible.com/t/how-to-detect-a-rescued-task-while-using-the-callbackbase/36270/2 "2022-02-08T19:24:54Z")

</div>

I meant `rescued`

I raised a proposal in [https://github.com/ansible/ansible/pull/76934](https://github.com/ansible/ansible/pull/76934) but it was not accepted, the implementation was a kind of to the one regarding the ignore\_errors, for similar reasons, since lib/ansible/plugins/strategy/ **init**.py seems to be the one in charge to run tasks and notify the callback.

There is a hint in the comment for closing the above-mentioned PR about a different alternative:

- The ‘rescue’ is not the only property of a task you might want to examine
- the ‘res’ property already includes the ‘task’ which should be able to access these same properties  
I tried to debug the res property in any given task by printing the content for the result in

def v2\_runner\_on\_failed(self, result, ignore\_errors=False):  
self.\_display.warning(str(result.\_result))

But given the below playbook:

- name: MyPlabook  
hosts: localhost  
connection: local  
tasks:
- block:
- name: Invalid URL on purpose  
uri:  
url: “[http://url.does.not.exist](http://url.does.not.exist)”  
method: “GET”  
rescue:
- name: Rescue block (perform recovery)  
debug:  
msg: “Something went wrong, cleaning up…”

The output looks like:

TASK [Invalid URL on purpose] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [localhost]: FAILED! =\> {“changed”: false, “elapsed”: 0, “msg”: “Status code was -1 and not [200]: Request failed: \<urlopen error [Errno 8] nodename nor servname provided, or not known\>”, “redirected”: false, “status”: -1, “url”: “[http://url.does.not.exist](http://url.does.not.exist)”}

**[WARNING]: {‘status’: -1, ‘url’: ‘[http://url.does.not.exist](http://url.does.not.exist)’, ‘changed’: False, ‘elapsed’: 0, ‘invocation’: {‘module\_args’: {‘force’: False, ‘remote\_src’: False, ‘status\_code’:**

**[200], ‘owner’: None, ‘body\_format’: ‘raw’, ‘client\_key’: None, ‘group’: None, ‘use\_proxy’: True, ‘headers’: {}, ‘unsafe\_writes’: False, ‘serole’: None, ‘setype’: None,**

**‘follow\_redirects’: ‘safe’, ‘return\_content’: False, ‘client\_cert’: None, ‘body’: None, ‘timeout’: 30, ‘url\_password’: None, ‘dest’: None, ‘selevel’: None, ‘force\_basic\_auth’:**

**False, ‘removes’: None, ‘http\_agent’: ‘ansible-httpget’, ‘src’: None, ‘url’: ‘[http://url.does.not.exist](http://url.does.not.exist)’, ‘seuser’: None, ‘method’: ‘GET’, ‘creates’: None, ‘unix\_socket’: None,**

**‘mode’: None, ‘url\_username’: None, ‘attributes’: None, ‘validate\_certs’: True}}, ‘redirected’: False, ‘msg’: 'Status code was -1 and not [200]: Request failed: \<urlopen error**

**[Errno 8] nodename nor servname provided, or not known\>', ‘\_ansible\_no\_log’: False}**

Unfortunately I cannot find any references in the result object that can help me to know that it was rescued. Any ideas what’s the data structure I need to search for to know if any given task was rescued?

Thanks

---

<div class="post-metadata">

**Author:** ![Victor\_Martinez](https://avatars.discourse-cdn.com/v4/letter/v/2acd7d/32.png) [@Victor\_Martinez](https://forum.ansible.com/u/Victor_Martinez)\
**Post date:** [April 20, 2022, 8:05pm UTC](https://forum.ansible.com/t/how-to-detect-a-rescued-task-while-using-the-callbackbase/36270/3 "2022-04-20T20:05:19Z")

</div>

Hi all,

I was not able to find the way to detect a rescued task within the CallbackBase. Any hints if that’s possible?

Thanks
