package_facts - use AnsibleModule.warn() for warnings

This commit is contained in:
Sam Doran 2019-10-14 12:30:46 -04:00 committed by Toshio Kuratomi
parent 7bb90999d3
commit 2b1e24fc49
3 changed files with 4 additions and 7 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- package_facts - use module warnings rather than a custom implementation for reporting warnings

View file

@ -18,8 +18,6 @@ def get_all_pkg_managers():
class PkgMgr(with_metaclass(ABCMeta, object)): class PkgMgr(with_metaclass(ABCMeta, object)):
warnings = []
@abstractmethod @abstractmethod
def is_available(self): def is_available(self):
# This method is supposed to return True/False if the package manager is currently installed/usable # This method is supposed to return True/False if the package manager is currently installed/usable

View file

@ -230,7 +230,7 @@ class RPM(LibMgr):
''' we expect the python bindings installed, but this gives warning if they are missing and we have rpm cli''' ''' 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() we_have_lib = super(RPM, self).is_available()
if not we_have_lib and get_bin_path('rpm'): if not we_have_lib and get_bin_path('rpm'):
self.warnings.append('Found "rpm" but %s' % (missing_required_lib('rpm'))) module.warn('Found "rpm" but %s' % (missing_required_lib('rpm')))
return we_have_lib return we_have_lib
@ -256,7 +256,7 @@ class APT(LibMgr):
if not we_have_lib: if not we_have_lib:
for exe in ('apt', 'apt-get', 'aptitude'): for exe in ('apt', 'apt-get', 'aptitude'):
if get_bin_path(exe): if get_bin_path(exe):
self.warnings.append('Found "%s" but %s' % (exe, missing_required_lib('apt'))) module.warn('Found "%s" but %s' % (exe, missing_required_lib('apt')))
break break
return we_have_lib return we_have_lib
@ -382,9 +382,6 @@ def main():
module.warn('Requested package manager %s was not usable by this module: %s' % (pkgmgr, to_text(e))) module.warn('Requested package manager %s was not usable by this module: %s' % (pkgmgr, to_text(e)))
continue continue
for warning in getattr(manager, 'warnings', []):
module.warn(warning)
except Exception as e: except Exception as e:
if pkgmgr in module.params['manager']: if pkgmgr in module.params['manager']:
module.warn('Failed to retrieve packages with %s: %s' % (pkgmgr, to_text(e))) module.warn('Failed to retrieve packages with %s: %s' % (pkgmgr, to_text(e)))