more useful messages when module failure (#43576)
* more useful messages when module failure specially if the 'interpreter' is not found * 1 less var * shebang can be none * remove typoes
This commit is contained in:
parent
a5774bd29a
commit
62d8c8fde6
2 changed files with 14 additions and 1 deletions
2
changelogs/fragments/missing_interpreter.yml
Normal file
2
changelogs/fragments/missing_interpreter.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- nicer message when we are missing interpreter
|
|
@ -60,6 +60,8 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
||||||
# Backwards compat: self._display isn't really needed, just import the global display and use that.
|
# Backwards compat: self._display isn't really needed, just import the global display and use that.
|
||||||
self._display = display
|
self._display = display
|
||||||
|
|
||||||
|
self._used_interpreter = None
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
""" Action Plugins should implement this method to perform their
|
""" Action Plugins should implement this method to perform their
|
||||||
|
@ -753,6 +755,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
||||||
if not shebang and module_style != 'binary':
|
if not shebang and module_style != 'binary':
|
||||||
raise AnsibleError("module (%s) is missing interpreter line" % module_name)
|
raise AnsibleError("module (%s) is missing interpreter line" % module_name)
|
||||||
|
|
||||||
|
self._used_interpreter = shebang
|
||||||
remote_module_path = None
|
remote_module_path = None
|
||||||
|
|
||||||
if not self._is_pipelining_enabled(module_style, wrap_async):
|
if not self._is_pipelining_enabled(module_style, wrap_async):
|
||||||
|
@ -896,12 +899,20 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# not valid json, lets try to capture error
|
# not valid json, lets try to capture error
|
||||||
data = dict(failed=True, _ansible_parsed=False)
|
data = dict(failed=True, _ansible_parsed=False)
|
||||||
data['msg'] = "MODULE FAILURE"
|
|
||||||
data['module_stdout'] = res.get('stdout', u'')
|
data['module_stdout'] = res.get('stdout', u'')
|
||||||
if 'stderr' in res:
|
if 'stderr' in res:
|
||||||
data['module_stderr'] = res['stderr']
|
data['module_stderr'] = res['stderr']
|
||||||
if res['stderr'].startswith(u'Traceback'):
|
if res['stderr'].startswith(u'Traceback'):
|
||||||
data['exception'] = res['stderr']
|
data['exception'] = res['stderr']
|
||||||
|
|
||||||
|
# try to figure out if we are missing interpreter
|
||||||
|
if self._used_interpreter is not None and '%s: No such file or directory' % self._used_interpreter.lstrip('!#') in data['module_stderr']:
|
||||||
|
data['msg'] = "The module failed to execute correctly, you probably need to set the interpreter."
|
||||||
|
else:
|
||||||
|
data['msg'] = "MODULE FAILURE"
|
||||||
|
|
||||||
|
data['msg'] += '\nSee stdout/stderr for the exact error'
|
||||||
|
|
||||||
if 'rc' in res:
|
if 'rc' in res:
|
||||||
data['rc'] = res['rc']
|
data['rc'] = res['rc']
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Add table
Reference in a new issue