From 894fbd6990634d8913e635d95c739c8648f6408c Mon Sep 17 00:00:00 2001 From: Slava <43387405+ptrNine@users.noreply.github.com> Date: Thu, 9 Dec 2021 20:47:27 +0300 Subject: [PATCH] pkg_mgr: prohibit pkg5 usage on Altlinux (#76457) Filter out the /usr/bin/pkg because on Altlinux it is actually the perl-Package (not Solaris package manager). Since the pkg5 takes precedence over apt, this workaround is required to select the suitable package manager on Altlinux. --- lib/ansible/module_utils/facts/system/pkg_mgr.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/facts/system/pkg_mgr.py b/lib/ansible/module_utils/facts/system/pkg_mgr.py index f290563cf87..c8980f56686 100644 --- a/lib/ansible/module_utils/facts/system/pkg_mgr.py +++ b/lib/ansible/module_utils/facts/system/pkg_mgr.py @@ -113,12 +113,22 @@ class PkgMgrFactCollector(BaseFactCollector): pkg_mgr_name = 'apt' return pkg_mgr_name + def pkg_mgrs(self, collected_facts): + # Filter out the /usr/bin/pkg because on Altlinux it is actually the + # perl-Package (not Solaris package manager). + # Since the pkg5 takes precedence over apt, this workaround + # is required to select the suitable package manager on Altlinux. + if collected_facts['ansible_os_family'] == 'Altlinux': + return filter(lambda pkg: pkg['path'] != '/usr/bin/pkg', PKG_MGRS) + else: + return PKG_MGRS + def collect(self, module=None, collected_facts=None): facts_dict = {} collected_facts = collected_facts or {} pkg_mgr_name = 'unknown' - for pkg in PKG_MGRS: + for pkg in self.pkg_mgrs(collected_facts): if os.path.exists(pkg['path']): pkg_mgr_name = pkg['name']