From 1da7340a99328d4d7d89bbcdb9986b4e6c975a67 Mon Sep 17 00:00:00 2001
From: Jesse Pretorius <jesse.pretorius@rackspace.co.uk>
Date: Tue, 14 Mar 2017 15:24:29 +0000
Subject: [PATCH] Force clean yum metadata when repo config changes

When changing the repo URL, the metadata does not reliably
update, resulting in the right URL being used, but the
wrong package list. This is why we force the metadata to be
cleaned out whenever the repo config changes.

Change-Id: I9bca9a89b58cd539dd5c224d6b141dc4d844bcc2
---
 tasks/galera_install_yum.yml | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tasks/galera_install_yum.yml b/tasks/galera_install_yum.yml
index a4fd62bb..4779dda3 100644
--- a/tasks/galera_install_yum.yml
+++ b/tasks/galera_install_yum.yml
@@ -61,12 +61,24 @@
     gpgcheck: yes
     enabled: yes
   register: add_repos
-  until: add_repos|success
+  until: add_repos | success
   retries: 5
   delay: 2
   tags:
     - galera-repos
 
+# When changing the repo URL, the metadata does
+# not reliably update, resulting in the right
+# URL being used, but the wrong package list.
+# This is why we force the metadata to be
+# cleaned out whenever the repo config changes.
+- name: Force the expiry of the repo metadata
+  command: "yum clean metadata"
+  when: add_repos | changed
+  tags:
+    - galera-repos
+    - skip_ansible_lint
+
 - name: Install percona repo
   yum:
     pkg: "{{ galera_percona_xtrabackup_repo.repo }}"