From 422e976649b986b82b1aa58568404866e31eb8b1 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Fri, 17 Jul 2020 15:43:19 -0400 Subject: [PATCH] [stable-2.10] apt - make errors more transparent (#70099) (#70478) Include error from apt Python library in module error output Co-authored-by: Andreas Schleifer (cherry picked from commit 7d7f15fc9b) Co-authored-by: Andreas Schleifer Co-authored-by: Andreas Schleifer --- .../fragments/70099-make-apt-errors-more-transparent.yaml | 2 ++ lib/ansible/modules/apt.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/70099-make-apt-errors-more-transparent.yaml diff --git a/changelogs/fragments/70099-make-apt-errors-more-transparent.yaml b/changelogs/fragments/70099-make-apt-errors-more-transparent.yaml new file mode 100644 index 00000000000..3328e1cad2b --- /dev/null +++ b/changelogs/fragments/70099-make-apt-errors-more-transparent.yaml @@ -0,0 +1,2 @@ +bugfixes: + - apt - include exception message from apt python library in error output diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py index d90d12dca63..bec7af9348f 100644 --- a/lib/ansible/modules/apt.py +++ b/lib/ansible/modules/apt.py @@ -1219,10 +1219,10 @@ def main(): elif p['state'] == 'absent': remove(module, packages, cache, p['purge'], force=force_yes, dpkg_options=dpkg_options, autoremove=autoremove) - except apt.cache.LockFailedException: - module.fail_json(msg="Failed to lock apt for exclusive operation") - except apt.cache.FetchFailedException: - module.fail_json(msg="Could not fetch updated apt files") + except apt.cache.LockFailedException as lockFailedException: + module.fail_json(msg="Failed to lock apt for exclusive operation: %s" % lockFailedException) + except apt.cache.FetchFailedException as fetchFailedException: + module.fail_json(msg="Could not fetch updated apt files: %s" % fetchFailedException) if __name__ == "__main__":