mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix fedora version dnf fact, default pkg_mgr detection per distro family (#43261)
* fix fedora version dnf fact, default pkg_mgr detection per distro family * loop over possible dnf/yum paths in case there are multiple canonical sources later in life Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
parent
7ba0d8f60e
commit
66b1adfc83
1 changed files with 18 additions and 12 deletions
|
@ -70,13 +70,19 @@ class PkgMgrFactCollector(BaseFactCollector):
|
||||||
_platform = 'Generic'
|
_platform = 'Generic'
|
||||||
required_facts = set(['distribution'])
|
required_facts = set(['distribution'])
|
||||||
|
|
||||||
def _check_rh_versions(self, collected_facts):
|
def _check_rh_versions(self, pkg_mgr_name, collected_facts):
|
||||||
if collected_facts['ansible_distribution'] == 'Fedora':
|
if collected_facts['ansible_distribution'] == 'Fedora':
|
||||||
try:
|
try:
|
||||||
if int(collected_facts['ansible_distribution_major_version']) < 15:
|
if int(collected_facts['ansible_distribution_major_version']) < 23:
|
||||||
pkg_mgr_name = 'yum'
|
for yum in [pkg_mgr for pkg_mgr in PKG_MGRS if pkg_mgr['name'] == 'yum']:
|
||||||
|
if os.path.exists(yum['path']):
|
||||||
|
pkg_mgr_name = 'yum'
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
pkg_mgr_name = 'dnf'
|
for dnf in [pkg_mgr for pkg_mgr in PKG_MGRS if pkg_mgr['name'] == 'dnf']:
|
||||||
|
if os.path.exists(dnf['path']):
|
||||||
|
pkg_mgr_name = 'dnf'
|
||||||
|
break
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# If there's some new magical Fedora version in the future,
|
# If there's some new magical Fedora version in the future,
|
||||||
# just default to dnf
|
# just default to dnf
|
||||||
|
@ -92,14 +98,14 @@ class PkgMgrFactCollector(BaseFactCollector):
|
||||||
if os.path.exists(pkg['path']):
|
if os.path.exists(pkg['path']):
|
||||||
pkg_mgr_name = pkg['name']
|
pkg_mgr_name = pkg['name']
|
||||||
|
|
||||||
# apt is easily installable and supported by distros other than those
|
# Handle distro family defaults when more than one package manager is
|
||||||
# that are debian based, this handles some of those scenarios as they
|
# installed, the ansible_fact entry should be the default package
|
||||||
# are reported/requested
|
# manager provided by the distro.
|
||||||
if pkg_mgr_name == 'apt' and collected_facts['ansible_os_family'] in ["RedHat", "Altlinux"]:
|
if collected_facts['ansible_os_family'] == "RedHat":
|
||||||
if collected_facts['ansible_os_family'] == 'RedHat':
|
if pkg_mgr_name not in ('yum', 'dnf'):
|
||||||
pkg_mgr_name = self._check_rh_versions(collected_facts)
|
pkg_mgr_name = self._check_rh_versions(pkg_mgr_name, collected_facts)
|
||||||
|
elif collected_facts['ansible_os_family'] == 'Altlinux':
|
||||||
elif collected_facts['ansible_os_family'] == 'Altlinux':
|
if pkg_mgr_name == 'apt':
|
||||||
pkg_mgr_name = 'apt_rpm'
|
pkg_mgr_name = 'apt_rpm'
|
||||||
|
|
||||||
# pacman has become available by distros other than those that are Arch
|
# pacman has become available by distros other than those that are Arch
|
||||||
|
|
Loading…
Reference in a new issue