Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg_mgr: prohibit pkg5 usage on Altlinux #76457

Merged
merged 1 commit into from Dec 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/ansible/module_utils/facts/system/pkg_mgr.py
Expand Up @@ -113,12 +113,22 @@ def _check_apt_flavor(self, pkg_mgr_name):
pkg_mgr_name = 'apt'
return pkg_mgr_name

def pkg_mgrs(self, collected_facts):
# Filter out the /usr/bin/pkg because on Altlinux it is actually the
# perl-Package (not Solaris package manager).
# Since the pkg5 takes precedence over apt, this workaround
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incorrect, apt-get has higher precedence than pkg

Copy link
Contributor Author

@ptrnine ptrnine Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's correct:

# A list of dicts. If there is a platform with more than one
# package manager, put the preferred one last. If there is an
# ansible module, use that as the value for the 'name' key.

Each next pkg['name'] in PKG_MGRS can rewrite the pkg_mgr_name:

for pkg in PKG_MGRS:
if os.path.exists(pkg['path']):
pkg_mgr_name = pkg['name']

And so pkg5 takes precedence over apt.

Copy link
Member

@bcoca bcoca Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, I didn't look at all the code and assumed assumed there was a break on match, its last, not first, found wins ... which makes me want to rewrite this section.

Not only can we have multiple package managers (add fact with list), but the traversal can be reversed + break to make it perform better. Another 'optimization' would be to create diff lists for OS families.

# is required to select the suitable package manager on Altlinux.
if collected_facts['ansible_os_family'] == 'Altlinux':
return filter(lambda pkg: pkg['path'] != '/usr/bin/pkg', PKG_MGRS)
else:
return PKG_MGRS

def collect(self, module=None, collected_facts=None):
facts_dict = {}
collected_facts = collected_facts or {}

pkg_mgr_name = 'unknown'
for pkg in PKG_MGRS:
for pkg in self.pkg_mgrs(collected_facts):
if os.path.exists(pkg['path']):
pkg_mgr_name = pkg['name']

Expand Down