Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ansible/ansible.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinifares23lab <62902848+inifares23lab@users.noreply.github.com>2022-11-02 19:02:04 +0300
committerGitHub <noreply@github.com>2022-11-02 19:02:04 +0300
commite2450d4886c43528ee8a870cc23cac73afdc6144 (patch)
treeb22aefe60751ee01a326882e5f5d92eff75a077f
parent26a477561168cd731c86fb1ceffb0394c81cb0a7 (diff)
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)
-rw-r--r--changelogs/fragments/apt-remove_allow-change-held-packages.yml2
-rw-r--r--lib/ansible/modules/apt.py30
-rw-r--r--test/integration/targets/apt/tasks/apt.yml51
3 files changed, 79 insertions, 4 deletions
diff --git a/changelogs/fragments/apt-remove_allow-change-held-packages.yml b/changelogs/fragments/apt-remove_allow-change-held-packages.yml
new file mode 100644
index 00000000000..0a10277947c
--- /dev/null
+++ b/changelogs/fragments/apt-remove_allow-change-held-packages.yml
@@ -0,0 +1,2 @@
+minor_changes:
+ - apt - add allow-change-held-packages option to apt remove (https://github.com/ansible/ansible/issues/78131)
diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py
index 1b7c5d2933d..ba0aed050d4 100644
--- a/lib/ansible/modules/apt.py
+++ b/lib/ansible/modules/apt.py
@@ -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:
diff --git a/test/integration/targets/apt/tasks/apt.yml b/test/integration/targets/apt/tasks/apt.yml
index d273eda71e2..a0bc19929f6 100644
--- a/test/integration/targets/apt/tasks/apt.yml
+++ b/test/integration/targets/apt/tasks/apt.yml
@@ -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: