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__":