mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 04:40:22 -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
|
@ -443,8 +443,13 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
|||
)
|
||||
mystat = self._execute_module(module_name='stat', module_args=module_args, task_vars=all_vars, tmp=tmp, delete_remote_tmp=(tmp is None))
|
||||
|
||||
if 'failed' in mystat and mystat['failed']:
|
||||
raise AnsibleError('Failed to get information on remote file (%s): %s' % (path, mystat['msg']))
|
||||
if mystat.get('failed'):
|
||||
msg = mystat.get('module_stderr')
|
||||
if not msg:
|
||||
msg = mystat.get('module_stdout')
|
||||
if not msg:
|
||||
msg = mystat.get('msg')
|
||||
raise AnsibleError('Failed to get information on remote file (%s): %s' % (path, msg))
|
||||
|
||||
if not mystat['stat']['exists']:
|
||||
# empty might be matched, 1 should never match, also backwards compatible
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue