From 588b9cead7637cc73cc8607e2460fea24cc6e2b0 Mon Sep 17 00:00:00 2001
From: Marc Gariepy <gariepy.marc@gmail.com>
Date: Thu, 15 Jun 2017 15:55:23 -0400
Subject: [PATCH] Move PrivateDevices before mysql password set

Move the PrivateDevices before we try to start the service the first time

Related-Bug: 1697531
Change-Id: I67ef7ba02ee652e9855b9cf4ba7a44a361844a83
---
 tasks/galera_install_yum.yml  | 32 ++++++++++++++++++++++++++++++++
 tasks/galera_post_install.yml | 15 ---------------
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/tasks/galera_install_yum.yml b/tasks/galera_install_yum.yml
index 4779dda3..5fc30f37 100644
--- a/tasks/galera_install_yum.yml
+++ b/tasks/galera_install_yum.yml
@@ -106,6 +106,38 @@
     - galera_server-config
     - galera-enable
 
+# This glue to make the upgrade works. when testing the galera_server role we install version 10.0
+# of mariadb and so the path doesn't exist, let's clean it up when we do upgrade testing the way
+# we do for other roles.
+# TODO: cleanup when we change upgrade test.
+- name: Check if we are on systemd service
+  stat:
+    path: "/etc/systemd/system/mariadb.service.d/"
+  register: systemd_mysql_service
+
+# See comments above 'galera_disable_privatedevices' in defaults/main.yml for
+# links to relevant bugs and discussion.
+- name: Remove PrivateDevices systemd options when in container
+  template:
+    src: without-privatedevices.conf.j2
+    dest: "/etc/systemd/system/mariadb.service.d/without-privatedevices.conf"
+  when:
+    - ansible_pkg_mgr == 'yum'
+    - systemd_mysql_service.stat.exists
+  notify:
+    - Reload the systemd daemon
+    - Restart mysql
+  tags:
+    - galera-config
+
+# TODO: remove name argument when we upgrade to ansible 2.4
+- name: Reload the systemd daemon
+  systemd:
+    daemon_reload: yes
+    name: mysql
+  when:
+    - systemd_mysql_service.stat.exists
+
 # NOTE(cloudnull): This is an idempotent shell task is it will only run once
 #  provided the "/etc/mysql/rhel_configured" exists. This tasks automates the
 #  MySQL secure setup which is done automatically in Ubuntu deployments.
diff --git a/tasks/galera_post_install.yml b/tasks/galera_post_install.yml
index a1b0bdc4..582adb39 100644
--- a/tasks/galera_post_install.yml
+++ b/tasks/galera_post_install.yml
@@ -112,21 +112,6 @@
   tags:
     - galera-config
 
-# See comments above 'galera_disable_privatedevices' in defaults/main.yml for
-# links to relevant bugs and discussion.
-- name: Remove PrivateDevices systemd options when in container
-  template:
-    src: without-privatedevices.conf.j2
-    dest: "/etc/systemd/system/mariadb.service.d/without-privatedevices.conf"
-  when:
-    - ansible_pkg_mgr == 'yum'
-    - ansible_service_mgr == 'systemd'
-  notify:
-    - Reload the systemd daemon
-    - Restart mysql
-  tags:
-    - galera-config
-
 - name: remove default mysql_safe_syslog
   file:
     path: "/etc/mysql/conf.d/mysqld_safe_syslog.cnf"