mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
apt: better error msg when update_cache fails (#37410)
This commit is contained in:
parent
6292fe1116
commit
a6d31b6fb1
2 changed files with 27 additions and 3 deletions
|
@ -956,14 +956,15 @@ def main():
|
||||||
tdelta = datetime.timedelta(seconds=p['cache_valid_time'])
|
tdelta = datetime.timedelta(seconds=p['cache_valid_time'])
|
||||||
if not mtimestamp + tdelta >= now:
|
if not mtimestamp + tdelta >= now:
|
||||||
# Retry to update the cache up to 3 times
|
# Retry to update the cache up to 3 times
|
||||||
|
err = ''
|
||||||
for retry in range(3):
|
for retry in range(3):
|
||||||
try:
|
try:
|
||||||
cache.update()
|
cache.update()
|
||||||
break
|
break
|
||||||
except apt.cache.FetchFailedException:
|
except apt.cache.FetchFailedException as e:
|
||||||
pass
|
err = to_native(e)
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='Failed to update apt cache.')
|
module.fail_json(msg='Failed to update apt cache: %s' % err)
|
||||||
cache.open(progress=None)
|
cache.open(progress=None)
|
||||||
updated_cache = True
|
updated_cache = True
|
||||||
mtimestamp, updated_cache_time = get_updated_cache_time()
|
mtimestamp, updated_cache_time = get_updated_cache_time()
|
||||||
|
|
|
@ -162,6 +162,29 @@
|
||||||
- "not apt_result.changed"
|
- "not apt_result.changed"
|
||||||
- "apt_result.failed"
|
- "apt_result.failed"
|
||||||
|
|
||||||
|
# https://github.com/ansible/ansible/issues/23155
|
||||||
|
- name: create a repo file
|
||||||
|
copy:
|
||||||
|
dest: /etc/apt/sources.list.d/non-existing.list
|
||||||
|
content: deb http://ppa.launchpad.net/non-existing trusty main
|
||||||
|
|
||||||
|
- name: test for sane error message
|
||||||
|
apt:
|
||||||
|
update_cache: yes
|
||||||
|
register: apt_result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: verify sane error message
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "'E:Failed to fetch' in apt_result['msg']"
|
||||||
|
- "'403' in apt_result['msg']"
|
||||||
|
|
||||||
|
- name: Clean up
|
||||||
|
file:
|
||||||
|
name: /etc/apt/sources.list.d/non-existing.list
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: autoclean during install
|
- name: autoclean during install
|
||||||
apt: pkg=hello state=present autoclean=yes
|
apt: pkg=hello state=present autoclean=yes
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue