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:
url: “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”}
[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