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

modules/apt: add support for apt-patterns #83070

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from

Conversation

jmechnich
Copy link

@jmechnich jmechnich commented Apr 16, 2024

SUMMARY

This small patch adds support for apt-patterns.

ISSUE TYPE
  • Feature Pull Request
ADDITIONAL INFORMATION

Support for apt-patterns makes it possible e.g. to express apt purge ?config-files using the apt module in contrast to working around using shell.

Only when using state=absent, the apt-pattern will end up as-is in the final call to apt on the remote machine as this is the most relevant use case for us and also in the examples of the apt-patterns man page. It is certainly possible to generalize for other packages states if required.

Example call: ansible -m apt -a "name=?config-files state=absent autoremove=yes purge=yes" ... will purge remnant configuration files from removed packages as well as unused packages in one call.

@ansibot ansibot added feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. module This issue/PR relates to a module. labels Apr 16, 2024
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Apr 18, 2024
@@ -634,8 +634,11 @@ def expand_pkgspec_from_fnmatches(m, pkgspec, cache):

pkgname_pattern, version_cmp, version = package_split(pkgspec_pattern)

if pkgname_pattern.startswith(('?', '~', '(?', '(~')):
Copy link
Member

Choose a reason for hiding this comment

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

@jmechnich Do you mind adding an integration test for this change? I am not quite sure if I understand how this change works.

Copy link
Author

@jmechnich jmechnich Apr 26, 2024

Choose a reason for hiding this comment

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

@Akasurde I cannot really think of a way to test this without actually calling apt-get or similar in a appropriately set up OS. Right now, the tests emulate certain operations using an artificial package cache.
The general idea of this patch is to exclude package names starting with ? or ~ from normal processing as they are not legal patterns for i.e. apt-cache operations.
The issue with testing this in the realm of ansible is mainly that the effect of those patterns is determined on each target host, individually, at execution time.
Maybe it is sufficient that the other tests are still working as expected?

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request. module This issue/PR relates to a module. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants