mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
now catches lock exceptoins on apt and returns friendly message instead of
traceback Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
This commit is contained in:
parent
f46721add1
commit
4a2276bb4b
1 changed files with 34 additions and 30 deletions
64
library/apt
64
library/apt
|
@ -226,41 +226,45 @@ def main():
|
||||||
p = module.params
|
p = module.params
|
||||||
install_recommends = p['install_recommends']
|
install_recommends = p['install_recommends']
|
||||||
|
|
||||||
cache = apt.Cache()
|
try:
|
||||||
if p['default_release']:
|
cache = apt.Cache()
|
||||||
apt_pkg.config['APT::Default-Release'] = p['default_release']
|
if p['default_release']:
|
||||||
# reopen cache w/ modified config
|
apt_pkg.config['APT::Default-Release'] = p['default_release']
|
||||||
cache.open(progress=None)
|
# reopen cache w/ modified config
|
||||||
|
cache.open(progress=None)
|
||||||
|
|
||||||
if p['update_cache']:
|
if p['update_cache']:
|
||||||
cache.update()
|
cache.update()
|
||||||
cache.open(progress=None)
|
cache.open(progress=None)
|
||||||
if not p['package']:
|
if not p['package']:
|
||||||
module.exit_json(changed=False)
|
module.exit_json(changed=False)
|
||||||
|
|
||||||
force_yes = p['force']
|
force_yes = p['force']
|
||||||
|
|
||||||
if p['upgrade']:
|
if p['upgrade']:
|
||||||
upgrade(module, p['upgrade'])
|
upgrade(module, p['upgrade'])
|
||||||
|
|
||||||
packages = p['package'].split(',')
|
packages = p['package'].split(',')
|
||||||
latest = p['state'] == 'latest'
|
latest = p['state'] == 'latest'
|
||||||
for package in packages:
|
for package in packages:
|
||||||
if package.count('=') > 1:
|
if package.count('=') > 1:
|
||||||
module.fail_json(msg="invalid package spec: %s" % package)
|
module.fail_json(msg="invalid package spec: %s" % package)
|
||||||
if latest and '=' in package:
|
if latest and '=' in package:
|
||||||
module.fail_json(msg='version number inconsistent with state=latest: %s' % package)
|
module.fail_json(msg='version number inconsistent with state=latest: %s' % package)
|
||||||
|
|
||||||
if p['state'] == 'latest':
|
if p['state'] == 'latest':
|
||||||
install(module, packages, cache, upgrade=True,
|
install(module, packages, cache, upgrade=True,
|
||||||
default_release=p['default_release'],
|
default_release=p['default_release'],
|
||||||
install_recommends=install_recommends,
|
install_recommends=install_recommends,
|
||||||
force=force_yes)
|
force=force_yes)
|
||||||
elif p['state'] in [ 'installed', 'present' ]:
|
elif p['state'] in [ 'installed', 'present' ]:
|
||||||
install(module, packages, cache, default_release=p['default_release'],
|
install(module, packages, cache, default_release=p['default_release'],
|
||||||
install_recommends=install_recommends,force=force_yes)
|
install_recommends=install_recommends,force=force_yes)
|
||||||
elif p['state'] in [ 'removed', 'absent' ]:
|
elif p['state'] in [ 'removed', 'absent' ]:
|
||||||
remove(module, packages, cache, p['purge'])
|
remove(module, packages, cache, p['purge'])
|
||||||
|
|
||||||
|
except LockFailedException:
|
||||||
|
module.fail_json(msg="Failed to lock apt for exclusive operation")
|
||||||
|
|
||||||
# this is magic, see lib/ansible/module_common.py
|
# this is magic, see lib/ansible/module_common.py
|
||||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||||
|
|
Loading…
Reference in a new issue