apt: ignore fail_on_autoremove and allow_downgrade when using aptitude (#81445)

* apt: ignore fail_on_autoremove and allow_downgrade when using aptitude

* fail_on_autoremove (--no-remove) and allow_downgrade (--allow-downgrades)
  parameters are only valid for apt-get and not for aptitude. Ignore them when
  aptitude is detected and used.

Fixes: #77868
pull/81593/head
Abhijeet Kasurde 9 months ago committed by GitHub
parent 5deb4ee991
commit 2e6d849bdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
---
bugfixes:
- apt - ignore fail_on_autoremove and allow_downgrade parameters when using aptitude (https://github.com/ansible/ansible/issues/77868).

@ -104,6 +104,7 @@ options:
- This option enables the named package and version to replace an already installed higher version of that package.
- Note that setting O(allow_downgrade=true) can make this module behave in a non-idempotent way.
- (The task could end up with a set of packages that does not match the complete list of specified packages to install).
- 'O(allow_downgrade) is only supported by C(apt) and will be ignored if C(aptitude) is detected or specified.'
aliases: [ allow-downgrade, allow_downgrades, allow-downgrades ]
type: bool
default: 'no'
@ -171,7 +172,8 @@ options:
description:
- 'Corresponds to the C(--no-remove) option for C(apt).'
- 'If V(true), it is ensured that no packages will be removed or the task will fail.'
- 'O(fail_on_autoremove) is only supported with O(state) except V(absent)'
- 'O(fail_on_autoremove) is only supported with O(state) except V(absent).'
- 'O(fail_on_autoremove) is only supported by C(apt) and will be ignored if C(aptitude) is detected or specified.'
type: bool
default: 'no'
version_added: "2.11"
@ -1091,13 +1093,24 @@ def upgrade(m, mode="yes", force=False, default_release=None,
force_yes = ''
if fail_on_autoremove:
fail_on_autoremove = '--no-remove'
if apt_cmd == APT_GET_CMD:
fail_on_autoremove = '--no-remove'
else:
m.warn("APTITUDE does not support '--no-remove', ignoring the 'fail_on_autoremove' parameter.")
fail_on_autoremove = ''
else:
fail_on_autoremove = ''
allow_unauthenticated = '--allow-unauthenticated' if allow_unauthenticated else ''
allow_downgrade = '--allow-downgrades' if allow_downgrade else ''
if allow_downgrade:
if apt_cmd == APT_GET_CMD:
allow_downgrade = '--allow-downgrades'
else:
m.warn("APTITUDE does not support '--allow-downgrades', ignoring the 'allow_downgrade' parameter.")
allow_downgrade = ''
else:
allow_downgrade = ''
if apt_cmd is None:
if use_apt_get:

@ -400,6 +400,8 @@
- { upgrade_type: safe, force_apt_get: True }
- { upgrade_type: full, force_apt_get: True }
- include_tasks: "upgrade_scenarios.yml"
- name: Remove aptitude if not originally present
apt:
pkg: aptitude

@ -0,0 +1,25 @@
# See https://github.com/ansible/ansible/issues/77868
# fail_on_autoremove is not valid parameter for aptitude
- name: Use fail_on_autoremove using aptitude
apt:
upgrade: yes
fail_on_autoremove: yes
register: fail_on_autoremove_result
- name: Check if fail_on_autoremove does not fail with aptitude
assert:
that:
- not fail_on_autoremove_result.failed
# See https://github.com/ansible/ansible/issues/77868
# allow_downgrade is not valid parameter for aptitude
- name: Use allow_downgrade using aptitude
apt:
upgrade: yes
allow_downgrade: yes
register: allow_downgrade_result
- name: Check if allow_downgrade does not fail with aptitude
assert:
that:
- not allow_downgrade_result.failed
Loading…
Cancel
Save