From e53982cd09fac486ffae6ca263389d8174e8ab9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20A=2E=20Rodr=C3=ADguez?= Date: Tue, 12 Oct 2021 12:24:40 -0300 Subject: [PATCH] The apt module won't work with python-apt < 0.8.9 (such as on Ubuntu 10.04) (#75993) * Check if deb file to deploy has architectures attribute, fixes ansible#47277 --- ...fails-to-deploy-deb-when-has-no-architecture-attribute.yml | 2 ++ lib/ansible/modules/apt.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/47277-fails-to-deploy-deb-when-has-no-architecture-attribute.yml diff --git a/changelogs/fragments/47277-fails-to-deploy-deb-when-has-no-architecture-attribute.yml b/changelogs/fragments/47277-fails-to-deploy-deb-when-has-no-architecture-attribute.yml new file mode 100644 index 00000000000..e9a10aecafb --- /dev/null +++ b/changelogs/fragments/47277-fails-to-deploy-deb-when-has-no-architecture-attribute.yml @@ -0,0 +1,2 @@ +bugfixes: + - apt - fails to deploy deb file to old debian systems using python-apt < 0.8.9 (https://github.com/ansible/ansible/issues/47277) diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py index 5a00a214017..c0cfe025cb0 100644 --- a/lib/ansible/modules/apt.py +++ b/lib/ansible/modules/apt.py @@ -787,10 +787,10 @@ def install_deb(m, debs, cache, force, fail_on_autoremove, install_recommends, a pkgs_to_install = [] for deb_file in debs.split(','): try: - pkg = apt.debfile.DebPackage(deb_file) + pkg = apt.debfile.DebPackage(deb_file, cache=apt.Cache()) pkg_name = get_field_of_deb(m, deb_file, "Package") pkg_version = get_field_of_deb(m, deb_file, "Version") - if len(apt_pkg.get_architectures()) > 1: + if hasattr(apt_pkg, 'get_architectures') and len(apt_pkg.get_architectures()) > 1: pkg_arch = get_field_of_deb(m, deb_file, "Architecture") pkg_key = "%s:%s" % (pkg_name, pkg_arch) else: