From fe278202f2117b1822807969f94e32a54a5db761 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Tue, 15 Mar 2016 20:31:40 -0700 Subject: [PATCH] Fix saving of tracebacks on module failure --- lib/ansible/plugins/action/__init__.py | 13 ++++++------- lib/ansible/plugins/action/synchronize.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 917e16dec3..392b670406 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -506,13 +506,12 @@ class ActionBase(with_metaclass(ABCMeta, object)): except ValueError: # not valid json, lets try to capture error data = dict(failed=True, parsed=False) - if 'stderr' in res and res['stderr'].startswith(u'Traceback'): - data['exception'] = res['stderr'] - else: - data['msg'] = "MODULE FAILURE" - data['module_stdout'] = res.get('stdout', u'') - if 'stderr' in res: - data['module_stderr'] = res['stderr'] + 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'] # pre-split stdout into lines, if stdout is in the data and there # isn't already a stdout_lines value there diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py index 9b267844b8..c0845d97f2 100644 --- a/lib/ansible/plugins/action/synchronize.py +++ b/lib/ansible/plugins/action/synchronize.py @@ -327,6 +327,6 @@ class ActionModule(ActionBase): if 'SyntaxError' in result.get('exception', result.get('msg', '')): # Emit a warning about using python3 because synchronize is # somewhat unique in running on localhost - result['traceback'] = result['msg'] + result['exception'] = result['msg'] result['msg'] = 'SyntaxError parsing module. Perhaps invoking "python" on your local (or delegate_to) machine invokes python3. You can set ansible_python_interpreter for localhost (or the delegate_to machine) to the location of python2 to fix this' return result