1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pkg_mgr: fixed apt_rpm detection (#43769)

Instead of checking the distribution name (which apparently is tricky to find out)
check if /usr/bin/apt-get is managed by RPM.

Fixes #43539
This commit is contained in:
Alexey Sheplyakov 2018-08-10 23:16:15 +04:00 committed by Brian Coca
parent 9be3a7dde5
commit 37361d9b0b

View file

@ -19,6 +19,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import os import os
import subprocess
from ansible.module_utils.facts.collector import BaseFactCollector from ansible.module_utils.facts.collector import BaseFactCollector
@ -89,6 +90,23 @@ class PkgMgrFactCollector(BaseFactCollector):
pkg_mgr_name = 'dnf' pkg_mgr_name = 'dnf'
return pkg_mgr_name return pkg_mgr_name
def _check_apt_flavor(self, pkg_mgr_name):
# Check if '/usr/bin/apt' is APT-RPM or an ordinary (dpkg-based) APT.
# There's rpm package on Debian, so checking if /usr/bin/rpm exists
# is not enough. Instead ask RPM if /usr/bin/apt-get belongs to some
# RPM package.
rpm_query = '/usr/bin/rpm -q --whatprovides /usr/bin/apt-get'.split()
if os.path.exists('/usr/bin/rpm'):
with open(os.devnull, 'w') as null:
try:
subprocess.check_call(rpm_query, stdout=null, stderr=null)
pkg_mgr_name = 'apt_rpm'
except subprocess.CalledProcessError:
# No apt-get in RPM database. Looks like Debian/Ubuntu
# with rpm package installed
pkg_mgr_name = 'apt'
return pkg_mgr_name
def collect(self, module=None, collected_facts=None): def collect(self, module=None, collected_facts=None):
facts_dict = {} facts_dict = {}
collected_facts = collected_facts or {} collected_facts = collected_facts or {}
@ -108,6 +126,10 @@ class PkgMgrFactCollector(BaseFactCollector):
if pkg_mgr_name == 'apt': if pkg_mgr_name == 'apt':
pkg_mgr_name = 'apt_rpm' pkg_mgr_name = 'apt_rpm'
# Check if /usr/bin/apt-get is ordinary (dpkg-based) APT or APT-RPM
if pkg_mgr_name == 'apt':
pkg_mgr_name = self._check_apt_flavor(pkg_mgr_name)
# pacman has become available by distros other than those that are Arch # pacman has become available by distros other than those that are Arch
# based by virtue of a dependency to the systemd mkosi project, this # based by virtue of a dependency to the systemd mkosi project, this
# handles some of those scenarios as they are reported/requested # handles some of those scenarios as they are reported/requested