mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Fix pkg_mgr fact on OpenBSD (#30725)
* Fix pkg_mgr fact on OpenBSD Add a OpenBSDPkgMgrFactCollector that hardcodes pkg_mgr to 'openbsd_pkg'. The ansible collector will choose the OpenBSD collector if the system is OpenBSD and the 'Generic' one otherwise. This removes PkgMgrFactCollectors depenency on the 'system' fact being in collected_facts, which also avoids ordering issues (if the pkg mgr fact is collected before the system fact...) Fixes #30623
This commit is contained in:
@@ -33,6 +33,7 @@ from ansible.module_utils.facts.system.fips import FipsFactCollector
|
||||
from ansible.module_utils.facts.system.local import LocalFactCollector
|
||||
from ansible.module_utils.facts.system.lsb import LSBFactCollector
|
||||
from ansible.module_utils.facts.system.pkg_mgr import PkgMgrFactCollector
|
||||
from ansible.module_utils.facts.system.pkg_mgr import OpenBSDPkgMgrFactCollector
|
||||
from ansible.module_utils.facts.system.platform import PlatformFactCollector
|
||||
from ansible.module_utils.facts.system.python import PythonFactCollector
|
||||
from ansible.module_utils.facts.system.selinux import SelinuxFactCollector
|
||||
@@ -110,6 +111,7 @@ collectors = [ApparmorFactCollector,
|
||||
SunOSNetworkCollector,
|
||||
|
||||
PkgMgrFactCollector,
|
||||
OpenBSDPkgMgrFactCollector,
|
||||
PlatformFactCollector,
|
||||
PythonFactCollector,
|
||||
SelinuxFactCollector,
|
||||
|
||||
@@ -50,20 +50,28 @@ PKG_MGRS = [{'path': '/usr/bin/yum', 'name': 'yum'},
|
||||
]
|
||||
|
||||
|
||||
class OpenBSDPkgMgrFactCollector(BaseFactCollector):
|
||||
name = 'pkg_mgr'
|
||||
_fact_ids = set()
|
||||
_platform = 'OpenBSD'
|
||||
|
||||
def collect(self, module=None, collected_facts=None):
|
||||
facts_dict = {}
|
||||
|
||||
facts_dict['pkg_mgr'] = 'openbsd_pkg'
|
||||
return facts_dict
|
||||
|
||||
|
||||
# the fact ends up being 'pkg_mgr' so stick with that naming/spelling
|
||||
class PkgMgrFactCollector(BaseFactCollector):
|
||||
name = 'pkg_mgr'
|
||||
_fact_ids = set()
|
||||
_platform = 'Generic'
|
||||
|
||||
def collect(self, module=None, collected_facts=None):
|
||||
facts_dict = {}
|
||||
collected_facts = collected_facts or {}
|
||||
|
||||
pkg_mgr_name = None
|
||||
if collected_facts.get('system') == 'OpenBSD':
|
||||
facts_dict['pkg_mgr'] = 'openbsd_pkg'
|
||||
return facts_dict
|
||||
|
||||
pkg_mgr_name = 'unknown'
|
||||
for pkg in PKG_MGRS:
|
||||
if os.path.exists(pkg['path']):
|
||||
|
||||
Reference in New Issue
Block a user