From f02081b391a5767b1309c048be778e278c8bd033 Mon Sep 17 00:00:00 2001 From: 0x546f6d-W <69774548+yctomwang@users.noreply.github.com> Date: Wed, 13 Mar 2024 02:10:50 +1100 Subject: [PATCH] Fix discrepancy in behaviour between apt-get clean and its equivalent ansible.builtin.apt: clean=True (#82800) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added integration test for issue 82611 regarding discrepency between apt-get clean and ansible.builtin.apt: clean * fixed new line issue * Implementation of bug fix for 82611 Fixed discrepancy in behaviour between apt-get clean and its equivalent ansible.builtin.apt: clean=True Co-authored-by: Martin Krizek --------- Co-authored-by: Martin Krizek --- ...nment_apt_clean_with_ansible_apt_clean.yml | 2 ++ lib/ansible/modules/apt.py | 2 +- test/integration/targets/apt/tasks/apt.yml | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/82611_fix_alignment_apt_clean_with_ansible_apt_clean.yml diff --git a/changelogs/fragments/82611_fix_alignment_apt_clean_with_ansible_apt_clean.yml b/changelogs/fragments/82611_fix_alignment_apt_clean_with_ansible_apt_clean.yml new file mode 100644 index 00000000000..bca3cfdf00d --- /dev/null +++ b/changelogs/fragments/82611_fix_alignment_apt_clean_with_ansible_apt_clean.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible.builtin.apt - calling clean = true does not properly clean certain cache files such as /var/cache/apt/pkgcache.bin and /var/cache/apt/pkgcache.bin (https://github.com/ansible/ansible/issues/82611) diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py index 98a641aa66f..33d33731067 100644 --- a/lib/ansible/modules/apt.py +++ b/lib/ansible/modules/apt.py @@ -1315,7 +1315,7 @@ def main(): aptclean_stdout, aptclean_stderr, aptclean_diff = aptclean(module) # If there is nothing else to do exit. This will set state as # changed based on if the cache was updated. - if not p['package'] and not p['upgrade'] and not p['deb']: + if not p['package'] and p['upgrade'] == 'no' and not p['deb']: module.exit_json( changed=True, msg=aptclean_stdout, diff --git a/test/integration/targets/apt/tasks/apt.yml b/test/integration/targets/apt/tasks/apt.yml index a0bc19929f6..55ab51d21d2 100644 --- a/test/integration/targets/apt/tasks/apt.yml +++ b/test/integration/targets/apt/tasks/apt.yml @@ -594,3 +594,26 @@ - elpa-yaml-mode state: absent purge: yes + +# https://github.com/ansible/ansible/issues/82611 +- name: clean apt cache + apt: + clean: true + +- name: check for /var/cache/apt/pkgcache.bin + stat: + path: /var/cache/apt/pkgcache.bin + register: pkgcache_bin + +- name: check for /var/cache/apt/srcpkgcache.bin + stat: + path: /var/cache/apt/srcpkgcache.bin + register: srcpkgcache_bin + +- name: verify apt cache files are cleaned + assert: + that: + - not pkgcache_bin.stat.exists + - not srcpkgcache_bin.stat.exists + fail_msg: "apt cache files still exist." + success_msg: "apt cache files are cleaned."