How to detect a rescued task while using the CallbackBase?

29 views
Skip to first unread message

Victor Martinez

unread,
Feb 1, 2022, 12:27:31 PMFeb 1
to Ansible Development
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

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

Thanks

Victor Martinez

unread,
Feb 8, 2022, 2:24:55 PMFeb 8
to Ansible Development
I meant `rescued`

I raised a proposal in 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:
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"}

[WARNING]: {'status': -1, 'url': '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', '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

Victor Martinez

unread,
Apr 20, 2022, 4:05:19 PMApr 20
to Ansible Development
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

Reply all
Reply to author
Forward
0 new messages