Fix cache update after initial apt_repository fail

If apt_repository fails to update the apt cache after updating the
configuration, retries don't register there was a change and so no
attempt is made to update the cache by the module on the second attempt.
This failure can result in a failure to install packages.

This change adds an apt module task to update the cache if the
apt_repository task registers a change. This means updating the cache
will get retried on failure and no longer fail silently.

Backport includes: https://review.openstack.org/547471

Change-Id: Id059dbec3466cb1ef3ea567249f52384a8ade515
Partial-Bug: #1750656
(cherry picked from commit 23bd341129)
This commit is contained in:
Jesse Pretorius 2018-02-22 14:48:19 +00:00 committed by Jesse Pretorius (odyssey4me)
parent 212991c1ca
commit cffd1ebd45
1 changed files with 35 additions and 7 deletions

View File

@ -46,27 +46,55 @@
tags:
- rabbitmq-apt-keys
# When updating the cache in the apt_repository
# task, and the update fails, a retry does not
# detect a change the second attempt and therefore
# does not update the cache, resulting in a changed
# repo config, but no updated cache. To work around
# this bug we implement the change of repo config
# and the cache update as two seperate tasks.
- name: Add rabbitmq repo
apt_repository:
repo: "{{ rabbitmq_repo.repo }}"
state: "{{ rabbitmq_repo.state }}"
filename: "{{ rabbitmq_repo.filename | default(omit) }}"
register: add_repos
until: add_repos|success
retries: 5
delay: 2
update_cache: no
register: add_rabbitmq_repos
when:
- rabbitmq_install_method == 'external_repo'
tags:
- rabbitmq-repos
# When updating the cache in the apt_repository
# task, and the update fails, a retry does not
# detect a change the second attempt and therefore
# does not update the cache, resulting in a changed
# repo config, but no updated cache. To work around
# this bug we implement the change of repo config
# and the cache update as two seperate tasks.
- name: Add erlang repo
apt_repository:
repo: "{{ rabbitmq_erlang_repo.repo }}"
state: "{{ rabbitmq_erlang_repo.state }}"
filename: "{{ rabbitmq_erlang_repo.filename | default(omit) }}"
register: add_repos
until: add_repos|success
update_cache: no
register: add_erlang_repos
tags:
- rabbitmq-repos
# Due to our Ansible strategy, a skipped task does not
# have a dictionary result, so we have to cater to the
# situation where either of the apt_repository tasks
# may not have the results dict in the register. As
# such we validate that the register is a mapping (dict).
- name: Update Apt cache
apt:
update_cache: yes
when:
- (add_rabbitmq_repos is mapping and add_rabbitmq_repos | changed) or
(add_erlang_repos is mapping and add_erlang_repos | changed)
register: update_apt_cache
until: update_apt_cache | success
retries: 5
delay: 2
tags:
@ -79,7 +107,7 @@
update_cache: yes
cache_valid_time: "{{ cache_timeout }}"
register: install_packages
until: install_packages|success
until: install_packages | success
retries: 5
delay: 2
tags: