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 puts responsibility for updating the cache on the apt module
task, this means updating the cache will get retried on failure and no
longer fail silently.

The changes made include:
- the two apt_repository tasks have their update_cache parameter set to
  no so it is clear where any update happens and there is no unnecessary
  duplication of cache updates.
- the use of retries is removed given the tasks no longer need to make
  use of the network.
- the apt_repository task result variables have been given unique names
  to ensure that the cache is updated if only the galera repository is
  added.

In addition, this cherry-pick separates out the cache update step from
the install task so that the update is not performed for every item.

Change-Id: I91b7929113f720bc3c55343c481096657376302f
Partial-bug: 1750656
(cherry picked from commit 7596eaa889)
This commit is contained in:
git-harry 2018-02-20 20:57:00 +00:00
parent 686462880c
commit ea7b8b253b
1 changed files with 14 additions and 10 deletions

View File

@ -63,10 +63,8 @@
repo: "{{ galera_repo.repo }}"
filename: "{{ galera_repo.filename | default(omit) }}"
state: "{{ galera_repo.state }}"
register: add_repos
until: add_repos|success
retries: 5
delay: 2
update_cache: "no"
register: add_galera_repo
tags:
- galera-repos
@ -75,10 +73,8 @@
repo: "{{ galera_percona_xtrabackup_repo.repo }}"
filename: "{{ galera_percona_xtrabackup_repo.filename | default(omit) }}"
state: "{{ (use_percona_upstream | bool) | ternary('present','absent') }}"
register: add_repos
until: add_repos|success
retries: 5
delay: 2
update_cache: "no"
register: add_percona_repo
tags:
- percona-repos
@ -99,12 +95,20 @@
mode: "0755"
backup: yes
- name: Update Apt cache
apt:
update_cache: yes
cache_valid_time: "{{ (add_galera_repo | changed or add_percona_repo | changed) | ternary('0', cache_timeout) }}"
register: update_apt_cache
until: update_apt_cache|success
retries: 5
delay: 2
- name: Install galera_server role remote packages (apt)
apt:
name: "{{ item }}"
state: "{{ galera_server_package_state }}"
update_cache: yes
cache_valid_time: "{{ (add_repos | changed) | ternary('0', cache_timeout) }}"
update_cache: no
with_items:
- "{{ galera_packages_list | selectattr('enabled') | rejectattr('local_pkg') | sum(attribute='packages', start=[]) }}"