mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
clarify package facts errors and warnings (#56060)
* clarify package facts errors and warnings fixes #56056
This commit is contained in:
parent
6f1ff8eb8e
commit
615db8e6f4
2 changed files with 17 additions and 4 deletions
2
changelogs/fragments/package_facts_clarify.yml
Normal file
2
changelogs/fragments/package_facts_clarify.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- clarify error messages for 'auto' and missing libs, add missing lib msg for rpm.
|
|
@ -155,7 +155,7 @@ ansible_facts:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native, to_text
|
from ansible.module_utils._text import to_native, to_text
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||||
from ansible.module_utils.common.process import get_bin_path
|
from ansible.module_utils.common.process import get_bin_path
|
||||||
from ansible.module_utils.facts.packages import LibMgr, CLIMgr, get_all_pkg_managers
|
from ansible.module_utils.facts.packages import LibMgr, CLIMgr, get_all_pkg_managers
|
||||||
|
|
||||||
|
@ -174,6 +174,13 @@ class RPM(LibMgr):
|
||||||
epoch=package[self._lib.RPMTAG_EPOCH],
|
epoch=package[self._lib.RPMTAG_EPOCH],
|
||||||
arch=package[self._lib.RPMTAG_ARCH],)
|
arch=package[self._lib.RPMTAG_ARCH],)
|
||||||
|
|
||||||
|
def is_available(self):
|
||||||
|
''' we expect the python bindings installed, but this gives warning if they are missing and we have rpm cli'''
|
||||||
|
we_have_lib = super(RPM, self).is_available()
|
||||||
|
if not we_have_lib and get_bin_path('rpm'):
|
||||||
|
self.warnings.append('Found "rpm" but %s' % (missing_required_lib('rpm')))
|
||||||
|
return we_have_lib
|
||||||
|
|
||||||
|
|
||||||
class APT(LibMgr):
|
class APT(LibMgr):
|
||||||
|
|
||||||
|
@ -195,9 +202,9 @@ class APT(LibMgr):
|
||||||
''' we expect the python bindings installed, but if there is apt/apt-get give warning about missing bindings'''
|
''' we expect the python bindings installed, but if there is apt/apt-get give warning about missing bindings'''
|
||||||
we_have_lib = super(APT, self).is_available()
|
we_have_lib = super(APT, self).is_available()
|
||||||
if not we_have_lib:
|
if not we_have_lib:
|
||||||
for exe in ('apt', 'apt-get'):
|
for exe in ('apt', 'apt-get', 'aptitude'):
|
||||||
if get_bin_path(exe):
|
if get_bin_path(exe):
|
||||||
self.warnings.append('Found "%s" but python bindings are missing, so we cannot get package information.' % exe)
|
self.warnings.append('Found "%s" but %s' % (exe, missing_required_lib('apt')))
|
||||||
break
|
break
|
||||||
return we_have_lib
|
return we_have_lib
|
||||||
|
|
||||||
|
@ -291,7 +298,11 @@ def main():
|
||||||
|
|
||||||
unsupported = set(managers).difference(PKG_MANAGER_NAMES)
|
unsupported = set(managers).difference(PKG_MANAGER_NAMES)
|
||||||
if unsupported:
|
if unsupported:
|
||||||
module.fail_json(msg='Unsupported package managers requested: %s' % (', '.join(unsupported)))
|
if 'auto' in module.params['manager']:
|
||||||
|
msg = 'Could not auto detect a usable package manager, check warnings for details.'
|
||||||
|
else:
|
||||||
|
msg = 'Unsupported package managers requested: %s' % (', '.join(unsupported))
|
||||||
|
module.fail_json(msg=msg)
|
||||||
|
|
||||||
found = 0
|
found = 0
|
||||||
seen = set()
|
seen = set()
|
||||||
|
|
Loading…
Reference in a new issue