apt: Report change when package is removed (#83547)

While upgrade process removes a package, module should
report changed=True instead of changed=False

Fixes: #46314

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/81364/merge
Abhijeet Kasurde 4 months ago committed by GitHub
parent 33565f3774
commit 504f5b1230
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- apt - report changed=True when some packages are being removed (https://github.com/ansible/ansible/issues/46314).

@ -381,8 +381,8 @@ from ansible.module_utils.six import string_types
from ansible.module_utils.urls import fetch_file
DPKG_OPTIONS = 'force-confdef,force-confold'
APT_GET_ZERO = "\n0 upgraded, 0 newly installed"
APTITUDE_ZERO = "\n0 packages upgraded, 0 newly installed"
APT_GET_ZERO = "\n0 upgraded, 0 newly installed, 0 to remove"
APTITUDE_ZERO = "\n0 packages upgraded, 0 newly installed, 0 to remove"
APT_LISTS_PATH = "/var/lib/apt/lists"
APT_UPDATE_SUCCESS_STAMP_PATH = "/var/lib/apt/periodic/update-success-stamp"
APT_MARK_INVALID_OP = 'Invalid operation'

@ -384,6 +384,8 @@
- { upgrade_type: safe, force_apt_get: True }
- { upgrade_type: full, force_apt_get: True }
- include_tasks: "upgrade_autoremove.yml"
- name: (Re-)Install aptitude, run same tests again
apt:
pkg: aptitude
@ -401,6 +403,7 @@
- { upgrade_type: full, force_apt_get: True }
- include_tasks: "upgrade_scenarios.yml"
- include_tasks: "upgrade_autoremove.yml"
- name: Remove aptitude if not originally present
apt:

@ -0,0 +1,76 @@
# https://github.com/ansible/ansible/issues/46314
- block:
- name: Remove upgrades from the equation
apt:
upgrade: true
state: present
update_cache: true
- name: Install foobar, installs foo as a dependency
apt:
name: foobar=1.0.0
allow_unauthenticated: true
- name: Check foobar version
shell: dpkg -s foobar | grep Version | awk '{print $2}'
register: foobar_version
- name: Ensure the correct version of foobar has been installed
assert:
that:
- "'1.0.0' in foobar_version.stdout"
- name: Remove foobar, leaving behind its dependency foo
apt:
name: foobar=1.0.0
state: absent
- name: Test autoremove + upgrade (check mode)
apt:
autoremove: true
upgrade: true
diff: true
check_mode: true
register: autoremove_check_mode
- name: Test autoremove + upgrade
apt:
autoremove: true
upgrade: true
diff: true
register: autoremove
- name: Check that something is changed
assert:
that:
- autoremove.changed
- autoremove_check_mode.changed
- name: Check foo version
shell: dpkg -s foo | grep Version | awk '{print $2}'
register: foo_version
- name: Check that old version removed correctly
assert:
that:
- "'1.0.1' not in foo_version.stdout"
- "{{ foo_version.changed }}"
- name: Test autoremove + upgrade (Idempotant)
apt:
autoremove: true
upgrade: true
diff: true
register: second_upgrade_result
- name: Check that nothing has changed (Idempotant)
assert:
that:
- "second_upgrade_result.changed == false"
always:
- name: Clean up
apt:
pkg: foo,foobar
state: absent
autoclean: true
Loading…
Cancel
Save