From 570379ef985c5645ac8cb6996fa6ce22e40c3c9a Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 8 Jun 2022 21:58:55 +0200 Subject: [PATCH] Do not crash callbacks if exception is not a string. (#77781) --- changelogs/fragments/77781-callback-crash.yml | 2 ++ lib/ansible/plugins/callback/__init__.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/77781-callback-crash.yml diff --git a/changelogs/fragments/77781-callback-crash.yml b/changelogs/fragments/77781-callback-crash.yml new file mode 100644 index 00000000000..21129beb0d9 --- /dev/null +++ b/changelogs/fragments/77781-callback-crash.yml @@ -0,0 +1,2 @@ +bugfixes: + - "callback plugins - do not crash when ``exception`` passed from a module is not a string (https://github.com/ansible/ansible/issues/75726, https://github.com/ansible/ansible/pull/77781)." diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index 0620f493725..c6f556a05bd 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -299,12 +299,13 @@ class CallbackBase(AnsiblePlugin): if 'exception' in result: msg = "An exception occurred during task execution. " + exception_str = to_text(result['exception']) if self._display.verbosity < 3: # extract just the actual error message from the exception text - error = result['exception'].strip().split('\n')[-1] + error = exception_str.strip().split('\n')[-1] msg += "To see the full traceback, use -vvv. The error was: %s" % error else: - msg = "The full traceback is:\n" + result['exception'] + msg = "The full traceback is:\n" + exception_str del result['exception'] self._display.display(msg, color=C.COLOR_ERROR, stderr=use_stderr)