mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Report detailed error when internal remote functions fail
This is a redesign in how plugins call _remote_checksum(). - _remote_stat() has been modified to report the real error as AnsiblError - Action plugin **unarchive** calls _remote_stat() directly instead of _remote_checksum() - Action plugin **unarchive** also handles the exceptions directly - Ensure get_exception() returns native text Two other action plugins, **template** and **fetch**, also do a remote checksum. In **template** we already call _remote_stat(), just like we now do for unarchive, in **fetch** we do call _remote_checksum() and we make the exact same mistake as the unarchive plugin. So that one could use a redesign as well. This fixes #19494 Before: ``` [dag@moria ansible.testing]$ ansible-playbook -v test137.yml Using /home/dag/home-made/ansible.testing/ansible.cfg as config file PLAY [localhost] ****************************************************************************************************** TASK [unarchive] ****************************************************************************************************** fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "python isn't present on the system. Unable to compute checksum"} PLAY RECAP ****************************************************************************************************** localhost : ok=0 changed=0 unreachable=0 failed=1 ``` After: ``` [dag@moria ansible.testing]$ ansible-playbook -v test137.yml Using /home/dag/home-made/ansible.testing/ansible.cfg as config file PLAY [localhost] ************************************************************************************************************* TASK [unarchive] ************************************************************************************************************* fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to get information on remote file (/tmp/): sudo: unknown user: foobar\nsudo: unable to initialize policy plugin\n"} PLAY RECAP ******************************************************************************************************************* localhost : ok=0 changed=0 unreachable=0 failed=1 ```
This commit is contained in:
parent
2597c1236d
commit
93cfe73a76
3 changed files with 21 additions and 12 deletions
|
@ -22,6 +22,7 @@ import os
|
|||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.constants import mk_boolean as boolean
|
||||
|
||||
|
@ -79,19 +80,21 @@ class ActionModule(ActionBase):
|
|||
if not remote_src:
|
||||
try:
|
||||
source = self._loader.get_real_file(self._find_needle('files', source))
|
||||
except AnsibleError as e:
|
||||
except AnsibleError:
|
||||
result['failed'] = True
|
||||
result['msg'] = to_native(e)
|
||||
result['msg'] = to_native(get_exception())
|
||||
self._remove_tmp_path(tmp)
|
||||
return result
|
||||
|
||||
remote_checksum = self._remote_checksum(dest, all_vars=task_vars, follow=True)
|
||||
if remote_checksum == '4':
|
||||
try:
|
||||
remote_stat = self._execute_remote_stat(dest, all_vars=task_vars, follow=True)
|
||||
except AnsibleError:
|
||||
result['failed'] = True
|
||||
result['msg'] = "python isn't present on the system. Unable to compute checksum"
|
||||
result['msg'] = to_native(get_exception())
|
||||
self._remove_tmp_path(tmp)
|
||||
return result
|
||||
elif remote_checksum != '3':
|
||||
|
||||
if not remote_stat['exists'] or not remote_stat['isdir']:
|
||||
result['failed'] = True
|
||||
result['msg'] = "dest '%s' must be an existing dir" % dest
|
||||
self._remove_tmp_path(tmp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue