Skip to content

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

Open
jmechnich wants to merge 3 commits intoansible:develfrom
UB-Mannheim:support-apt-patterns
Open

modules/apt: add support for apt-patterns#83070
jmechnich wants to merge 3 commits intoansible:develfrom
UB-Mannheim:support-apt-patterns

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

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?

Copy link
Author

Choose a reason for hiding this comment

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

@Akasurde sorry for reviving this old PR after such a long time...is there anything I can still do to get this accepted?

@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
@ansibot ansibot added the stale_pr This PR has not been pushed to for more than one year. label Apr 22, 2025
@ansibot ansibot removed stale_pr This PR has not been pushed to for more than one year. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Sep 25, 2025
@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Sep 26, 2025
@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Sep 26, 2025
@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 Oct 10, 2025
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.

4 participants