diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2024-11-12 14:36:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-12 14:36:26 +0100 |
commit | e404bc17f7551281c7019d7373d59a95ff1c8723 (patch) | |
tree | b5f7824edca567ec5f9e543ae3add38178654cdd /lib | |
parent | Fix runas become SYSTEM logic (#84280) (diff) | |
download | ansible-e404bc17f7551281c7019d7373d59a95ff1c8723.tar.xz ansible-e404bc17f7551281c7019d7373d59a95ff1c8723.zip |
package_facts fix empty packages on foreign mgr (#83855)
* package_facts fix empty packages on foreign mgr
return the first package manager that provides output
add tests with fake rpm on apt machines
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/modules/package_facts.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/ansible/modules/package_facts.py b/lib/ansible/modules/package_facts.py index df10c4694d..e1dc026093 100644 --- a/lib/ansible/modules/package_facts.py +++ b/lib/ansible/modules/package_facts.py @@ -460,7 +460,7 @@ def main(): # get supported pkg managers PKG_MANAGERS = get_all_pkg_managers() - PKG_MANAGER_NAMES = [x.lower() for x in PKG_MANAGERS.keys()] + PKG_MANAGER_NAMES = sorted([x.lower() for x in PKG_MANAGERS.keys()]) # add aliases PKG_MANAGER_NAMES.extend([alias for alist in ALIASES.values() for alias in alist]) @@ -510,12 +510,24 @@ def main(): manager = PKG_MANAGERS[pkgmgr]() try: + packages_found = {} if manager.is_available(handle_exceptions=False): - found += 1 try: - packages.update(manager.get_packages()) + packages_found = manager.get_packages() except Exception as e: module.warn('Failed to retrieve packages with %s: %s' % (pkgmgr, to_text(e))) + + # only consider 'found' if it results in something + if packages_found: + found += 1 + for k in packages_found.keys(): + if k in packages: + packages[k].extend(packages_found[k]) + else: + packages[k] = packages_found[k] + else: + module.warn('Found "%s" but no associated packages' % (pkgmgr)) + 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))) |