From 14cced1d77d6b2ad74d8aa5a19538dbe0e6bc506 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Thu, 22 Feb 2018 14:48:19 +0000 Subject: [PATCH] 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 23bd341129bc9fc6449f3b1f38f07fb4914aa298) --- tasks/install_apt.yml | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/tasks/install_apt.yml b/tasks/install_apt.yml index e398988f..2c513842 100644 --- a/tasks/install_apt.yml +++ b/tasks/install_apt.yml @@ -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: