From 7d7f15fc9b6db995d896d8a6ad31168ce83afc7e Mon Sep 17 00:00:00 2001 From: Andreas Schleifer Date: Mon, 6 Jul 2020 18:20:09 +0200 Subject: [PATCH] apt - make errors more transparent (#70099) Include error from apt Python library in module error output 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 e7b1450e97f..5eb63a57a85 100644 --- a/lib/ansible/modules/apt.py +++ b/lib/ansible/modules/apt.py @@ -1247,10 +1247,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__":