added apt lock_timeout (#74095)
* added apt lock_timeout should help control issues with apt db being locked out also cleanup imports
This commit is contained in:
parent
c7473828c7
commit
bb7b17fded
2 changed files with 151 additions and 131 deletions
2
changelogs/fragments/apt_lock_timeout.yml
Normal file
2
changelogs/fragments/apt_lock_timeout.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- apt, added a 'lock_timeout' to be more resilient when encountering the apt db already locked and handle it w/o haveing to rerun task.
|
|
@ -158,6 +158,13 @@ options:
|
|||
type: bool
|
||||
default: 'no'
|
||||
version_added: "2.4"
|
||||
lock_timeout:
|
||||
description:
|
||||
- How many seconds will this action wait to aquire a lock on the apt db.
|
||||
- Sometimes there is a transitory lock and this will retry at least until timeout is hit.
|
||||
type: int
|
||||
default: 60
|
||||
version_added: "2.12"
|
||||
requirements:
|
||||
- python-apt (python 2)
|
||||
- python3-apt (python 3)
|
||||
|
@ -312,13 +319,12 @@ import datetime
|
|||
import fnmatch
|
||||
import itertools
|
||||
import os
|
||||
import shutil
|
||||
import random
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import random
|
||||
import time
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.common.respawn import has_respawned, probe_interpreters_for_module, respawn_module
|
||||
|
@ -1079,6 +1085,7 @@ def main():
|
|||
only_upgrade=dict(type='bool', default=False),
|
||||
force_apt_get=dict(type='bool', default=False),
|
||||
allow_unauthenticated=dict(type='bool', default=False, aliases=['allow-unauthenticated']),
|
||||
lock_timeout=dict(type='int', default=60),
|
||||
),
|
||||
mutually_exclusive=[['deb', 'package', 'upgrade']],
|
||||
required_one_of=[['autoremove', 'deb', 'package', 'update_cache', 'upgrade']],
|
||||
|
@ -1166,7 +1173,13 @@ def main():
|
|||
fail_on_autoremove = p['fail_on_autoremove']
|
||||
autoclean = p['autoclean']
|
||||
|
||||
# Get the cache object
|
||||
# max times we'll retry
|
||||
deadline = time.time() + p['lock_timeout']
|
||||
|
||||
# keep running on lock issues unless timeout or resolution is hit.
|
||||
while True:
|
||||
|
||||
# Get the cache object, this has 3 retries built in
|
||||
cache = get_cache(module)
|
||||
|
||||
try:
|
||||
|
@ -1301,10 +1314,15 @@ def main():
|
|||
remove(module, packages, cache, p['purge'], force=force_yes, dpkg_options=dpkg_options, autoremove=autoremove)
|
||||
|
||||
except apt.cache.LockFailedException as lockFailedException:
|
||||
if time.time() < deadline:
|
||||
continue
|
||||
module.fail_json(msg="Failed to lock apt for exclusive operation: %s" % lockFailedException)
|
||||
except apt.cache.FetchFailedException as fetchFailedException:
|
||||
module.fail_json(msg="Could not fetch updated apt files: %s" % fetchFailedException)
|
||||
|
||||
# got here w/o exception and/or exit???
|
||||
module.exit_json({'failed': True, 'msg': 'Unexpected code path taken,we really should have exited before, this is a bug'})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue