added --allow-change-held-packages for apt remove (#78203)

* added --allow-change-held-packages for apt remove

* add tests for apt remove (allow_change_held_packages=yes)

* add changelog for apt remove (allow-change-held-packages=yes)

* update tests for apt remove (allow_change_held_packages=yes)
pull/79295/head
inifares23lab 2 years ago committed by GitHub
parent 26a4775611
commit e2450d4886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- apt - add allow-change-held-packages option to apt remove (https://github.com/ansible/ansible/issues/78131)

@ -929,7 +929,8 @@ def install_deb(
def remove(m, pkgspec, cache, purge=False, force=False,
dpkg_options=expand_dpkg_options(DPKG_OPTIONS), autoremove=False):
dpkg_options=expand_dpkg_options(DPKG_OPTIONS), autoremove=False,
allow_change_held_packages=False):
pkg_list = []
pkgspec = expand_pkgspec_from_fnmatches(m, pkgspec, cache)
for package in pkgspec:
@ -962,7 +963,21 @@ def remove(m, pkgspec, cache, purge=False, force=False,
else:
check_arg = ''
cmd = "%s -q -y %s %s %s %s %s remove %s" % (APT_GET_CMD, dpkg_options, purge, force_yes, autoremove, check_arg, packages)
if allow_change_held_packages:
allow_change_held_packages = '--allow-change-held-packages'
else:
allow_change_held_packages = ''
cmd = "%s -q -y %s %s %s %s %s %s remove %s" % (
APT_GET_CMD,
dpkg_options,
purge,
force_yes,
autoremove,
check_arg,
allow_change_held_packages,
packages
)
with PolicyRcD(m):
rc, out, err = m.run_command(cmd)
@ -1470,7 +1485,16 @@ def main():
else:
module.fail_json(**retvals)
elif p['state'] == 'absent':
remove(module, packages, cache, p['purge'], force=force_yes, dpkg_options=dpkg_options, autoremove=autoremove)
remove(
module,
packages,
cache,
p['purge'],
force=force_yes,
dpkg_options=dpkg_options,
autoremove=autoremove,
allow_change_held_packages=allow_change_held_packages
)
except apt.cache.LockFailedException as lockFailedException:
if time.time() < deadline:

@ -372,7 +372,7 @@
- libcaca-dev
- libslang2-dev
# https://github.com/ansible/ansible/issues/38995
# # https://github.com/ansible/ansible/issues/38995
- name: build-dep for a package
apt:
name: tree
@ -524,6 +524,55 @@
- "allow_change_held_packages_no_update is not changed"
- "allow_change_held_packages_hello_version.stdout == allow_change_held_packages_hello_version_again.stdout"
# Remove pkg on hold
- name: Put hello on hold
shell: apt-mark hold hello
- name: Get hold list
shell: apt-mark showhold
register: hello_hold
- name: Check that the package hello is on the hold list
assert:
that:
- "'hello' in hello_hold.stdout"
- name: Try removing package hello
apt:
name: hello
state: absent
register: package_removed
ignore_errors: true
- name: verify the package is not removed with dpkg
shell: dpkg -l hello
register: dpkg_result
- name: Verify that package was not removed
assert:
that:
- package_removed is failed
- dpkg_result is success
- name: Try removing package (allow_change_held_packages=yes)
apt:
name: hello
state: absent
allow_change_held_packages: yes
register: package_removed
- name: verify the package is removed with dpkg
shell: dpkg -l hello
register: dpkg_result
ignore_errors: true
- name: Verify that package removal was succesfull
assert:
that:
- package_removed is success
- dpkg_result is failed
- package_removed.changed
# Virtual package
- name: Install a virtual package
apt:

Loading…
Cancel
Save