From 27ac2fc67ce31c7e2b84598235d80b12e7e36c94 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Mon, 20 Aug 2018 14:59:56 -0500 Subject: [PATCH] Ensure that apt is always chosen on debian/ubuntu (#44413) One can install alternate packages managers on debuntu machines. However, doing so doesn't mean you want to suddenly start using them. Add in a check similar to the fedora yum/dnf check that sets apt as the pkg_mgr if the ansible_os_family is Debian. --- changelogs/fragments/zypper-on-ubuntu.yaml | 4 ++++ .../module_utils/facts/system/pkg_mgr.py | 4 ++++ .../targets/package/tasks/main.yml | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 changelogs/fragments/zypper-on-ubuntu.yaml diff --git a/changelogs/fragments/zypper-on-ubuntu.yaml b/changelogs/fragments/zypper-on-ubuntu.yaml new file mode 100644 index 00000000000..6afe40fc3b1 --- /dev/null +++ b/changelogs/fragments/zypper-on-ubuntu.yaml @@ -0,0 +1,4 @@ +bugfixes: + - Fixed an issue where ``ansible_facts.pkg_mgr`` would incorrectly set + to ``zypper`` on Debian/Ubuntu systems that happened to have the + command installed. diff --git a/lib/ansible/module_utils/facts/system/pkg_mgr.py b/lib/ansible/module_utils/facts/system/pkg_mgr.py index ec3a13de30e..3bb18343c8f 100644 --- a/lib/ansible/module_utils/facts/system/pkg_mgr.py +++ b/lib/ansible/module_utils/facts/system/pkg_mgr.py @@ -122,6 +122,10 @@ class PkgMgrFactCollector(BaseFactCollector): if collected_facts['ansible_os_family'] == "RedHat": if pkg_mgr_name not in ('yum', 'dnf'): pkg_mgr_name = self._check_rh_versions(pkg_mgr_name, collected_facts) + elif collected_facts['ansible_os_family'] == 'Debian' and pkg_mgr_name != 'apt': + # It's possible to install yum, dnf, zypper, rpm, etc inside of + # Debian. Doing so does not mean the system wants to use them. + pkg_mgr_name = 'apt' elif collected_facts['ansible_os_family'] == 'Altlinux': if pkg_mgr_name == 'apt': pkg_mgr_name = 'apt_rpm' diff --git a/test/integration/targets/package/tasks/main.yml b/test/integration/targets/package/tasks/main.yml index 0ce58739efb..4fc3a8a6796 100644 --- a/test/integration/targets/package/tasks/main.yml +++ b/test/integration/targets/package/tasks/main.yml @@ -46,6 +46,30 @@ setup: when: ansible_distribution == "Fedora" +# Verify correct default package manager for Debian/Ubuntu when Zypper installed +- block: + # Just make an executable file called "zypper" - installing zypper itself + # consistently is hard - and we're not going to use it + - name: install fake zypper + file: + state: touch + mode: 0755 + path: /usr/bin/zypper + - name: gather facts again + setup: + - name: validate output + assert: + that: + - 'ansible_pkg_mgr == "apt"' + always: + - name: remove fake zypper + file: + path: /usr/bin/zypper + state: absent + - name: gather facts again + setup: + when: ansible_os_family == "Debian" + ## ## package ##