Skip to content

apt: api fail issue when pkg pinned with high priority#85174

Open
rohit-bharmal wants to merge 7 commits into
ansible:develfrom
rohit-bharmal:devel
Open

apt: api fail issue when pkg pinned with high priority#85174
rohit-bharmal wants to merge 7 commits into
ansible:develfrom
rohit-bharmal:devel

Conversation

@rohit-bharmal

Copy link
Copy Markdown
SUMMARY

Fixes a bug in the apt module where installing a specific version of a package (like mypkg=1.2.3) fails if other versions are pinned with a higher APT priority (>1001).

Ansible was using APT's default candidate selection, which can ignore the version the user asked for. This update changes the logic to directly look for the requested version in the package cache, similar to how apt-get install pkg=version works.

This makes sure the correct version is installed if it exists, even if pinning would normally prevent it.

Fixes #85147

ISSUE TYPE
  • Bugfix Pull Request

@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. module This issue/PR relates to a module. has_issue needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels May 19, 2025
Comment thread lib/ansible/modules/apt.py
@Akasurde

Copy link
Copy Markdown
Member

@rohit-bharmal Tests are failing due to this change. Can you please check the reason for the failure? Thanks.

@webknjaz

Copy link
Copy Markdown
Member

@Akasurde FYI when you know that the CI is failing due to the PR patch, feel free to apply ci_verified. This is one of the daily maintenance tasks I'm doing.

@webknjaz webknjaz added the ci_verified Changes made in this PR are causing tests to fail. label May 26, 2025
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label May 27, 2025
Comment thread lib/ansible/modules/apt.py Outdated
@ansibot ansibot added stale_review Updates were made after the last review and the last review is more than 7 days old. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. ci_verified Changes made in this PR are causing tests to fail. labels May 28, 2025
@Akasurde

Copy link
Copy Markdown
Member

@rohit-bharmal Thanks for the update. Could you please add a test, something like this?

@rohit-bharmal

Copy link
Copy Markdown
Author

@rohit-bharmal Thanks for the update. Could you please add a test, something like this?

@Akasurde Will the same test work here as well? I believe it was added for the same priority-related functionality. Right?

@Akasurde

Akasurde commented Jun 2, 2025

Copy link
Copy Markdown
Member

@rohit-bharmal Thanks for the update. Could you please add a test, something like this?

@Akasurde Will the same test work here as well? I believe it was added for the same priority-related functionality. Right?

Yes, you need to set the priority to something higher than 1001 and then try installing package using =.

@rohit-bharmal

Copy link
Copy Markdown
Author

@rohit-bharmal Thanks for the update. Could you please add a test, something like this?

@Akasurde Will the same test work here as well? I believe it was added for the same priority-related functionality. Right?

Yes, you need to set the priority to something higher than 1001 and then try installing package using =.

What if I do change in the same script to update the priority to 1002? like below:

- name: Pin foo=1.0.0 copy: content: |- Package: foo Pin: version 1.0.0 Pin-Priority: 1002 dest: /etc/apt/preferences.d/foo

@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 Jun 10, 2025
@rohit-bharmal

Copy link
Copy Markdown
Author

@Akasurde I have added a test there!

@ansibot ansibot removed 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 Jun 17, 2025
@webknjaz

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@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 Jul 16, 2025
@rohit-bharmal rohit-bharmal requested a review from Akasurde July 28, 2025 07:51
Comment on lines +151 to +158
- name: Pin foo=1.0.0
copy:
content: |-
Package: foo
Pin: version 1.0.0
Pin-Priority: 1002
dest: /etc/apt/preferences.d/foo

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be done by modifying the previous task (which also copies data to the same destination file) instead?

@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue/PR relates to a bug. has_issue module This issue/PR relates to a module. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apt will fail when package pinned with high pin priority

6 participants