From 954f874085a473ea8944638c6eede6934be3f588 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 9 Feb 2019 19:05:01 +0000 Subject: [PATCH 1/2] issue #527: catch new-style module tracebacks like vanilla. --- ansible_mitogen/runner.py | 6 ++++++ tests/ansible/integration/runner/all.yml | 1 + .../runner/crashy_new_style_module.yml | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/ansible/integration/runner/crashy_new_style_module.yml diff --git a/ansible_mitogen/runner.py b/ansible_mitogen/runner.py index 56d29487..608a707f 100644 --- a/ansible_mitogen/runner.py +++ b/ansible_mitogen/runner.py @@ -42,6 +42,7 @@ import shlex import shutil import sys import tempfile +import traceback import types import mitogen.core @@ -871,6 +872,11 @@ class NewStyleRunner(ScriptRunner): except SystemExit: exc = sys.exc_info()[1] rc = exc.args[0] + except Exception: + # This writes to stderr by default. + traceback.print_exc() + rc = 1 + finally: self.atexit_wrapper.run_callbacks() diff --git a/tests/ansible/integration/runner/all.yml b/tests/ansible/integration/runner/all.yml index 32229fe9..dc23901f 100644 --- a/tests/ansible/integration/runner/all.yml +++ b/tests/ansible/integration/runner/all.yml @@ -1,5 +1,6 @@ - include: atexit.yml - include: builtin_command_module.yml +- include: crashy_new_style_module.yml - include: custom_bash_hashbang_argument.yml - include: custom_bash_old_style_module.yml - include: custom_bash_want_json_module.yml diff --git a/tests/ansible/integration/runner/crashy_new_style_module.yml b/tests/ansible/integration/runner/crashy_new_style_module.yml new file mode 100644 index 00000000..40ee7f88 --- /dev/null +++ b/tests/ansible/integration/runner/crashy_new_style_module.yml @@ -0,0 +1,18 @@ +# issue #527: catch exceptions from crashy modules. + +- name: integration/runner/crashy_new_style_module.yml + hosts: test-targets + tasks: + - custom_python_run_script: + script: kaboom + register: out + ignore_errors: true + + - assert: + that: + - not out.changed + - out.rc == 1 + - out.msg == "MODULE FAILURE" + - out.module_stdout == "" + - "'Traceback (most recent call last)' in out.module_stderr" + - "\"NameError: name 'kaboom' is not defined\" in out.module_stderr" From 8a2dcbf674f7e23062200d271f11d3b5f6509c4a Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 9 Feb 2019 19:13:16 +0000 Subject: [PATCH 2/2] docs: update Changelog; closes #527. --- docs/changelog.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5e572518..3b1e734f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -266,6 +266,11 @@ Fixes * `#499 `_: the ``allow_same_user`` Ansible configuration setting is respected. +* `#527 `_: crashes in modules are + trapped and reported in a manner that matches Ansible. In particular, a + module crash no longer leads to an exception that may crash the corresponding + action plug-in. + * `dc1d4251 `_: the ``synchronize`` module could fail with the Docker transport due to a missing attribute.