Fix apt making changes in check mode (#78496) (#78530)

* Don't actually update the cache in check mode

Add tests for updating the cache in check mode

* Don't mark packages as manually installed in check mode and add a test for it

* changelog

* Update test/integration/targets/apt/tasks/apt.yml

* fix test

(cherry picked from commit 3add5e9321)
pull/78687/head
Sloane Hertel 3 years ago committed by GitHub
parent b2553d162d
commit 702eadf21b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
bugfixes:
- apt - don't actually update the cache in check mode with update_cache=true.
- apt - don't mark existing packages as manually installed in check mode (https://github.com/ansible/ansible/issues/66413).

@ -809,7 +809,7 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,
status = True
data = dict(changed=False)
if not build_dep:
if not build_dep and not m.check_mode:
mark_installed_manually(m, package_names)
return (status, data)
@ -1332,7 +1332,8 @@ def main():
for retry in range(update_cache_retries):
try:
cache.update()
if not module.check_mode:
cache.update()
break
except apt.cache.FetchFailedException as e:
err = to_native(e)
@ -1347,7 +1348,7 @@ def main():
cache.open(progress=None)
mtimestamp, post_cache_update_time = get_updated_cache_time()
if updated_cache_time != post_cache_update_time:
if module.check_mode or updated_cache_time != post_cache_update_time:
updated_cache = True
updated_cache_time = post_cache_update_time

@ -83,12 +83,26 @@
- apt_install_fnmatch is changed
- apt_uninstall_fnmatch is changed
- name: Test update_cache 1 (check mode)
apt:
update_cache: true
cache_valid_time: 10
register: apt_update_cache_1_check_mode
check_mode: true
- name: Test update_cache 1
apt:
update_cache: true
cache_valid_time: 10
register: apt_update_cache_1
- name: Test update_cache 2 (check mode)
apt:
update_cache: true
cache_valid_time: 10
register: apt_update_cache_2_check_mode
check_mode: true
- name: Test update_cache 2
apt:
update_cache: true
@ -98,7 +112,9 @@
- name: verify update_cache
assert:
that:
- apt_update_cache_1_check_mode is changed
- apt_update_cache_1 is changed
- apt_update_cache_2_check_mode is not changed
- apt_update_cache_2 is not changed
- name: uninstall apt bindings with apt again

@ -196,6 +196,42 @@
name: foobar=1.0.0
allow_unauthenticated: yes
- name: mark foobar as auto for next test
shell: apt-mark auto foobar
- name: Install foobar (marked as manual) (check mode)
apt:
name: foobar=1.0.1
allow_unauthenticated: yes
check_mode: yes
register: manual_foobar_install_check_mode
- name: check foobar was not marked as manually installed by check mode
shell: apt-mark showmanual | grep foobar
ignore_errors: yes
register: showmanual
- assert:
that:
- manual_foobar_install_check_mode.changed
- "'foobar' not in showmanual.stdout"
- name: Install foobar (marked as manual)
apt:
name: foobar=1.0.1
allow_unauthenticated: yes
register: manual_foobar_install
- name: check foobar was marked as manually installed
shell: apt-mark showmanual | grep foobar
ignore_errors: yes
register: showmanual
- assert:
that:
- manual_foobar_install.changed
- "'foobar' in showmanual.stdout"
- name: Upgrade foobar to a version which does not depend on foo, autoremove should remove foo
apt:
upgrade: dist

Loading…
Cancel
Save