summaryrefslogtreecommitdiff
path: root/lib/ansible
diff options
context:
space:
mode:
authorinifares23lab <62902848+inifares23lab@users.noreply.github.com>2022-11-02 16:02:04 +0000
committerGitHub <noreply@github.com>2022-11-02 12:02:04 -0400
commite2450d4886c43528ee8a870cc23cac73afdc6144 (patch)
treeb22aefe60751ee01a326882e5f5d92eff75a077f /lib/ansible
parent26a477561168cd731c86fb1ceffb0394c81cb0a7 (diff)
downloadansible-e2450d4886c43528ee8a870cc23cac73afdc6144.tar.gz
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)
Diffstat (limited to 'lib/ansible')
-rw-r--r--lib/ansible/modules/apt.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py
index 1b7c5d2933..ba0aed050d 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: