clarify package facts errors and warnings (#56060)

* clarify package facts errors and warnings

  fixes #56056
pull/57065/head
Brian Coca 6 years ago committed by GitHub
parent 6f1ff8eb8e
commit 615db8e6f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save