From 615db8e6f4a9c7b6b81db3e7c7b194630b7536d2 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 28 May 2019 10:01:47 -0400 Subject: [PATCH] clarify package facts errors and warnings (#56060) * clarify package facts errors and warnings fixes #56056 --- .../fragments/package_facts_clarify.yml | 2 ++ .../modules/packaging/os/package_facts.py | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/package_facts_clarify.yml diff --git a/changelogs/fragments/package_facts_clarify.yml b/changelogs/fragments/package_facts_clarify.yml new file mode 100644 index 00000000000..2ac9f8aab8c --- /dev/null +++ b/changelogs/fragments/package_facts_clarify.yml @@ -0,0 +1,2 @@ +bugfixes: + - clarify error messages for 'auto' and missing libs, add missing lib msg for rpm. diff --git a/lib/ansible/modules/packaging/os/package_facts.py b/lib/ansible/modules/packaging/os/package_facts.py index c758025a07c..9f541aefe59 100644 --- a/lib/ansible/modules/packaging/os/package_facts.py +++ b/lib/ansible/modules/packaging/os/package_facts.py @@ -155,7 +155,7 @@ ansible_facts: ''' 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.facts.packages import LibMgr, CLIMgr, get_all_pkg_managers @@ -174,6 +174,13 @@ class RPM(LibMgr): epoch=package[self._lib.RPMTAG_EPOCH], 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): @@ -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_have_lib = super(APT, self).is_available() if not we_have_lib: - for exe in ('apt', 'apt-get'): + for exe in ('apt', 'apt-get', 'aptitude'): 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 return we_have_lib @@ -291,7 +298,11 @@ def main(): unsupported = set(managers).difference(PKG_MANAGER_NAMES) 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 seen = set()