mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Package facts apt fix (#55963)
* fixes for apt on package_facts * reverse order, apt is newer * moved warnings prop to base
This commit is contained in:
parent
edafa71f42
commit
24a46deef5
3 changed files with 19 additions and 0 deletions
2
changelogs/fragments/package_facts_apt_fix.yml
Normal file
2
changelogs/fragments/package_facts_apt_fix.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- For package_facts, correct information about apt being missing and fix missing attribute.
|
|
@ -18,6 +18,8 @@ def get_all_pkg_managers():
|
|||
|
||||
class PkgMgr(with_metaclass(ABCMeta, object)):
|
||||
|
||||
warnings = []
|
||||
|
||||
@abstractmethod
|
||||
def is_available(self):
|
||||
# This method is supposed to return True/False if the package manager is currently installed/usable
|
||||
|
|
|
@ -155,6 +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.common.process import get_bin_path
|
||||
from ansible.module_utils.facts.packages import LibMgr, CLIMgr, get_all_pkg_managers
|
||||
|
||||
|
||||
|
@ -189,6 +190,16 @@ class APT(LibMgr):
|
|||
self._cache = self._lib.Cache()
|
||||
return self._cache
|
||||
|
||||
def is_available(self):
|
||||
''' 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'):
|
||||
if get_bin_path(exe):
|
||||
self.warnings.append('Found "%s" but python bindings are missing, so we cannot get package information.' % exe)
|
||||
break
|
||||
return we_have_lib
|
||||
|
||||
def list_installed(self):
|
||||
return [pk for pk in self.pkg_cache.keys() if self.pkg_cache[pk].is_installed]
|
||||
|
||||
|
@ -299,11 +310,15 @@ def main():
|
|||
if manager.is_available():
|
||||
found += 1
|
||||
packages.update(manager.get_packages())
|
||||
|
||||
except Exception as e:
|
||||
if pkgmgr in module.params['manager']:
|
||||
module.warn('Requested package manager %s was not usable by this module: %s' % (pkgmgr, to_text(e)))
|
||||
continue
|
||||
|
||||
for warning in getattr(manager, 'warnings', []):
|
||||
module.warn(warning)
|
||||
|
||||
except Exception as e:
|
||||
if pkgmgr in module.params['manager']:
|
||||
module.warn('Failed to retrieve packages with %s: %s' % (pkgmgr, to_text(e)))
|
||||
|
|
Loading…
Reference in a new issue