Browse Source

When upgrading, only stop the service if it exists

In Id9c4f11b3536e7f9d510f5ef8e6d82a82a96adac we implemented a
failed_when condition to ignore the state of the service stop task
when `galera_ignore_cluster_state=true` is passed through.

Unfortunately, the omit filter does not work in a task context [1],
resulting in the task always failing because the omit placeholder
string is evaluated as true. This makes the task always fail when
running an upgrade.

In this patch we change the task flow to evaluate whether a service
exists, and if it does then to stop it - otherwise skip that task.
This should cater for the rolling replacement use-case and will
work in every other situation too.

[1] https://github.com/ansible/ansible/issues/25678

Change-Id: Ib26c807057b9114e02ad32c759a5028555788363
Jesse Pretorius 4 months ago
parent
commit
69e2c736a0
1 changed files with 16 additions and 1 deletions
  1. 16
    1
      tasks/galera_upgrade_pre.yml

+ 16
- 1
tasks/galera_upgrade_pre.yml View File

@@ -13,15 +13,30 @@
13 13
 # See the License for the specific language governing permissions and
14 14
 # limitations under the License.
15 15
 
16
+# When doing a rolling replacement of an existing cluster,
17
+# a service may not yet exist on the target host. This will
18
+# cause the service stop task to fail. To cater for this
19
+# we only try to stop the service is it exists.
20
+- name: Check whether a mysql service exists yet
21
+  shell: >-
22
+    systemctl list-unit-files --state=enabled --type=service | grep "^mysql.service .* enabled$"
23
+  args:
24
+    executable: /bin/bash
25
+    warn: no
26
+  changed_when: false
27
+  failed_when: false
28
+  register: _mysql_service_exists
29
+
16 30
 - name: Stop MariaDB
17 31
   systemd:
18 32
     name: mysql
19 33
     state: stopped
20
-  failed_when: "{{ (not galera_ignore_cluster_state | bool) | default(omit, false) }}"
21 34
   register: galera_restart_fall_back
22 35
   until: galera_restart_fall_back is success
23 36
   retries: 3
24 37
   delay: 5
38
+  when:
39
+    - _mysql_service_exists.rc == 0
25 40
 
26 41
 - name: UN-Install galera-server package
27 42
   package:

Loading…
Cancel
Save