apt: Consider timeout while invoking apt-get command (#85219)

* apt: Consider timeout while invoking apt-get command

* Apply timeout specified by user to apt-get command
  using '-o DPkg::Lock::Timeout=' syntax

Fixes: #78658

Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
(cherry picked from commit cace19f365)
pull/85383/head
Abhijeet Kasurde 6 months ago committed by Matt Clay
parent 865d69dab1
commit 73df36e7d0

@ -0,0 +1,3 @@
---
minor_changes:
- apt - consider lock timeout while invoking apt-get command (https://github.com/ansible/ansible/issues/78658).

@ -855,6 +855,7 @@ def install_deb(
allow_downgrade,
allow_change_held_packages,
dpkg_options,
lock_timeout,
):
changed = False
deps_to_install = []
@ -903,13 +904,14 @@ def install_deb(
# install the deps through apt
retvals = {}
if deps_to_install:
install_dpkg_options = f"{expand_dpkg_options(dpkg_options)} -o DPkg::Lock::Timeout={lock_timeout}"
(success, retvals) = install(m=m, pkgspec=deps_to_install, cache=cache,
install_recommends=install_recommends,
fail_on_autoremove=fail_on_autoremove,
allow_unauthenticated=allow_unauthenticated,
allow_downgrade=allow_downgrade,
allow_change_held_packages=allow_change_held_packages,
dpkg_options=expand_dpkg_options(dpkg_options))
dpkg_options=install_dpkg_options)
if not success:
m.fail_json(**retvals)
changed = retvals.get('changed', False)
@ -1269,7 +1271,7 @@ def main():
p = module.params
install_recommends = p['install_recommends']
dpkg_options = expand_dpkg_options(p['dpkg_options'])
dpkg_options = f"{expand_dpkg_options(p['dpkg_options'])} -o DPkg::Lock::Timeout={p['lock_timeout']}"
if not HAS_PYTHON_APT:
# This interpreter can't see the apt Python library- we'll do the following to try and fix that:
@ -1470,7 +1472,11 @@ def main():
allow_unauthenticated=allow_unauthenticated,
allow_change_held_packages=allow_change_held_packages,
allow_downgrade=allow_downgrade,
force=force_yes, fail_on_autoremove=fail_on_autoremove, dpkg_options=p['dpkg_options'])
force=force_yes,
fail_on_autoremove=fail_on_autoremove,
dpkg_options=p['dpkg_options'],
lock_timeout=p['lock_timeout']
)
unfiltered_packages = p['package'] or ()
packages = [package.strip() for package in unfiltered_packages if package != '*']

Loading…
Cancel
Save