From 1f7871584885a3a1652fd4f17cf7d5eb28e7d218 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 30 May 2017 22:09:43 +0200 Subject: [PATCH] apt: include arch in check for installed packages on multi-arch systems (#24846) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * apt: include arch in check for installed packages on multi-arch systems Thanks: Stefan Löwen Fixes: #24673 * add an integration test for apt's multi-arch handling --- lib/ansible/modules/packaging/os/apt.py | 7 +++- .../integration/targets/apt/defaults/main.yml | 1 + .../targets/apt/tasks/apt-multiarch.yml | 32 +++++++++++++++++++ test/integration/targets/apt/tasks/main.yml | 3 ++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/apt/defaults/main.yml create mode 100644 test/integration/targets/apt/tasks/apt-multiarch.yml diff --git a/lib/ansible/modules/packaging/os/apt.py b/lib/ansible/modules/packaging/os/apt.py index 3a723efcca7..54b1d9b14b8 100644 --- a/lib/ansible/modules/packaging/os/apt.py +++ b/lib/ansible/modules/packaging/os/apt.py @@ -571,8 +571,13 @@ def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated pkg = apt.debfile.DebPackage(deb_file) 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: + pkg_arch = get_field_of_deb(m, deb_file, "Architecture") + pkg_key = "%s:%s" % (pkg_name, pkg_arch) + else: + pkg_key = pkg_name try: - installed_pkg = apt.Cache()[pkg_name] + installed_pkg = apt.Cache()[pkg_key] installed_version = installed_pkg.installed.version if package_version_compare(pkg_version, installed_version) == 0: # Does not need to down-/upgrade, move on to next package diff --git a/test/integration/targets/apt/defaults/main.yml b/test/integration/targets/apt/defaults/main.yml new file mode 100644 index 00000000000..05a5780fd34 --- /dev/null +++ b/test/integration/targets/apt/defaults/main.yml @@ -0,0 +1 @@ +apt_foreign_arch: i386 diff --git a/test/integration/targets/apt/tasks/apt-multiarch.yml b/test/integration/targets/apt/tasks/apt-multiarch.yml new file mode 100644 index 00000000000..e0ade2bbc50 --- /dev/null +++ b/test/integration/targets/apt/tasks/apt-multiarch.yml @@ -0,0 +1,32 @@ +# verify that apt is handling multi-arch systems properly +- name: add architecture {{ apt_foreign_arch }} + command: dpkg --add-architecture {{ apt_foreign_arch }} + +- name: install hello:{{ apt_foreign_arch }} with apt + apt: pkg=hello:{{ apt_foreign_arch }} state=present update_cache=yes + +- name: uninstall hello:{{ apt_foreign_arch }} with apt + apt: pkg=hello:{{ apt_foreign_arch }} state=absent purge=yes + +- name: install deb file + apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ apt_foreign_arch }}.deb" + register: apt_multi_initial + +- name: install deb file again + apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ apt_foreign_arch }}.deb" + register: apt_multi_secondary + +- name: verify installation of hello:{{ apt_foreign_arch }} + assert: + that: + - "apt_multi_initial.changed" + - "not apt_multi_secondary.changed" + +- name: remove all {{ apt_foreign_arch }} packages + apt: + name: "*:{{ apt_foreign_arch }}" + state: absent + purge: yes + +- name: remove {{ apt_foreign_arch }} architecture + command: dpkg --remove-architecture {{ apt_foreign_arch }} diff --git a/test/integration/targets/apt/tasks/main.yml b/test/integration/targets/apt/tasks/main.yml index 552b543d2d3..29682d3ad98 100644 --- a/test/integration/targets/apt/tasks/main.yml +++ b/test/integration/targets/apt/tasks/main.yml @@ -18,5 +18,8 @@ - include: 'apt.yml' when: ansible_distribution in ('Ubuntu', 'Debian') +- include: 'apt-multiarch.yml' + when: ansible_distribution in ('Ubuntu', 'Debian') and ansible_userspace_architecture != apt_foreign_arch + - include: 'apt-builddep.yml' when: ansible_distribution in ('Ubuntu', 'Debian')