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

On Tuesday, 1 February 2022 at 17:27:31 UTC Victor Martinez wrote:

> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/b71217ce-7c7f-4a3b-82f9-b75800dcb3f6n%40googlegroups.com.

Reply via email to