Browse Source

Remove old service files before masking them

Masking a service creates a symlink from /etc/systemd/system/foo.service
to /dev/null. If we deleted them after masking then the service
effectively becomes unmasked.
Scott Dodson 6 years ago
parent
commit
0bcee6a1d5
1 changed files with 18 additions and 8 deletions
  1. 18 8
      roles/etcd/tasks/upgrade_static.yml

+ 18 - 8
roles/etcd/tasks/upgrade_static.yml

@@ -8,6 +8,24 @@
 - name: Verify cluster is healthy pre-upgrade
   command: "{{ etcdctlv2 }} cluster-health"
 
+- name: Check for old etcd service files
+  stat:
+    path: "{{ item }}"
+  with_items:
+  - "/etc/systemd/system/etcd.service"
+  - "/etc/systemd/system/etcd_container.service"
+  register: old_svc_files
+
+- name: Remove old etcd service files
+  file:
+    path: "{{ item.stat.path }}"
+    state: absent
+  with_items:
+  - "{{ old_svc_files.results }}"
+  when:
+  - item.stat.exists
+  - item.stat.isreg
+
 # We removed the ability to detect what was previously 'containerized'
 # Need to stop and disable this service, but might not be present.
 - name: Stop, disable and mask old etcd service
@@ -22,14 +40,6 @@
   - etcd_container
   failed_when: False
 
-- name: Remove old etcd service files
-  file:
-    path: "{{ item }}"
-    state: absent
-  with_items:
-  - "/etc/systemd/system/etcd.service"
-  - "/etc/systemd/system/etcd_container.service"
-
 - name: Remove nonexistent services
   command: "systemctl reset-failed"