Skip to content

Commit

Permalink
more useful messages when module failure (ansible#43576)
Browse files Browse the repository at this point in the history
* more useful messages when module failure

specially if the 'interpreter' is not found

* 1 less var

* shebang can be none

* remove typoes
  • Loading branch information
bcoca authored and ansibot committed Aug 2, 2018
1 parent a5774bd commit 62d8c8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/missing_interpreter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- nicer message when we are missing interpreter
13 changes: 12 additions & 1 deletion lib/ansible/plugins/action/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def __init__(self, task, connection, play_context, loader, templar, shared_loade
# Backwards compat: self._display isn't really needed, just import the global display and use that.
self._display = display

self._used_interpreter = None

@abstractmethod
def run(self, tmp=None, task_vars=None):
""" Action Plugins should implement this method to perform their
Expand Down Expand Up @@ -753,6 +755,7 @@ def _execute_module(self, module_name=None, module_args=None, tmp=None, task_var
if not shebang and module_style != 'binary':
raise AnsibleError("module (%s) is missing interpreter line" % module_name)

self._used_interpreter = shebang
remote_module_path = None

if not self._is_pipelining_enabled(module_style, wrap_async):
Expand Down Expand Up @@ -896,12 +899,20 @@ def _parse_returned_data(self, res):
except ValueError:
# not valid json, lets try to capture error
data = dict(failed=True, _ansible_parsed=False)
data['msg'] = "MODULE FAILURE"
data['module_stdout'] = res.get('stdout', u'')
if 'stderr' in res:
data['module_stderr'] = res['stderr']
if res['stderr'].startswith(u'Traceback'):
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:
data['rc'] = res['rc']
return data
Expand Down

0 comments on commit 62d8c8f

Please sign in to comment.