]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
purge: fix ubuntu purge when not using systemd
authorSébastien Han <seb@redhat.com>
Fri, 27 Jan 2017 10:33:37 +0000 (11:33 +0100)
committerAndrew Schoen <aschoen@redhat.com>
Tue, 31 Jan 2017 13:35:15 +0000 (07:35 -0600)
We now rely on the cli tool ceph-detect-init which will tell us the init
system in used on the distribution. We do this instead of the previous
lookup for systemd unit files to call the right task depending on the
init system.

Signed-off-by: Sébastien Han <seb@redhat.com>
(cherry picked from commit e371bd591c45ad9e18fda9fcd938b736044146e2)

infrastructure-playbooks/purge-cluster.yml

index 1637d7edc30b39070be94962365c331b75cc8127..ed4a4012ae4d29a010e7f72a6019f008d8f69fe1 100644 (file)
@@ -31,8 +31,7 @@
          invoking the playbook"
     when: ireallymeanit != 'yes'
 
-
-- name: gather facts and check if using systemd
+- name: gather facts and check init system
 
   vars:
     mon_group_name:       mons
   become: true
 
   tasks:
-  - name: are we using systemd
-    shell: "if [ -d /usr/lib/systemd ] ; then find /usr/lib/systemd/system -name 'ceph*' | wc -l ; else echo 0 ; fi"
-    register: systemd_unit_files
-
+  - name: detect init system
+    command: ceph-detect-init
+    register: init_system
 
 - name: purge ceph mds cluster
 
       name: ceph.target
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: ansible_service_mgr == 'systemd'
 
   - name: stop ceph mdss with systemd
     service:
       name: ceph-mds@{{ ansible_hostname }}
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: init_system.stdout == 'systemd'
 
   - name: stop ceph mdss
     shell: "service ceph status mds ; if [ $? == 0 ] ; then service ceph stop mds ; else echo ; fi"
-    when: ansible_os_family == 'RedHat'
+    when: init_system.stdout == 'sysvinit'
 
-# Ubuntu 14.04
   - name: stop ceph mdss on ubuntu
     command: initctl stop ceph-mds cluster={{ cluster }} id={{ ansible_hostname }}
     failed_when: false
-    when: ansible_distribution == 'Ubuntu'
+    when: init_system.stdout == 'upstart'
 
 
 - name: purge ceph rgw cluster
       name: ceph.target
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: ansible_service_mgr == 'systemd'
 
   - name: stop ceph rgws with systemd
     service:
       name: ceph-radosgw@rgw.{{ ansible_hostname }}
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: init_system.stdout == 'systemd'
 
   - name: stop ceph rgws
     shell: "service ceph-radosgw status ; if [ $? == 0 ] ; then service ceph-radosgw stop ; else echo ; fi"
-    when: ansible_os_family == 'RedHat'
+    when: init_system.stdout == 'sysvinit'
 
-# Ubuntu 14.04
   - name: stop ceph rgws on ubuntu
     command: initctl stop radosgw cluster={{ cluster }} id={{ ansible_hostname }}
     failed_when: false
-    when: ansible_distribution == 'Ubuntu'
+    when: init_system.stdout == 'upstart'
 
 
 - name: purge ceph rbd-mirror cluster
       name: ceph.target
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: ansible_service_mgr == 'systemd'
 
   - name: stop ceph rbd mirror with systemd
     service:
       name: ceph-rbd-mirror@admin.service
       state: stopped
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: init_system.stdout == 'systemd'
 
-# Ubuntu 14.04
   - name: stop ceph rbd mirror on ubuntu
     command: initctl stop ceph-rbd-mirror cluster={{ cluster }} id=admin
     failed_when: false
-    when: ansible_distribution == 'Ubuntu'
+    when: init_system.stdout == 'upstart'
 
 
 - name: purge ceph nfs cluster
       name: ceph.target
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: ansible_service_mgr == 'systemd'
 
   - name: stop ceph nfss with systemd
     service:
       name: nfs-ganesha
       state: stopped
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: init_system.stdout == 'systemd'
 
   - name: stop ceph nfss
     shell: "service nfs-ganesha status ; if [ $? == 0 ] ; then service nfs-ganesha stop ; else echo ; fi"
-    when: ansible_os_family == 'RedHat'
+    when: init_system.stdout == 'sysvinit'
 
-# Ubuntu 14.04
   - name: stop ceph nfss on ubuntu
     command: initctl stop nfs-ganesha
     failed_when: false
-    when: ansible_distribution == 'Ubuntu'
+    when: init_system.stdout == 'upstart'
 
 
 - name: purge ceph osd cluster
       name: ceph.target
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: ansible_service_mgr == 'systemd'
 
   - name: stop ceph-osd with systemd
     service:
       state: stopped
       enabled: no
     with_items: "{{ osd_ids.stdout_lines }}"
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: init_system.stdout == 'systemd'
 
-# before infernalis release, using sysvinit scripts
-# we use this test so we do not have to know which RPM contains the boot script
-# or where it is placed.
+  # before infernalis release, using sysvinit scripts
+  # we use this test so we do not have to know which RPM contains the boot script
+  # or where it is placed.
 
   - name: stop ceph osds
     shell: "service ceph status osd ; if [ $? == 0 ] ; then service ceph stop osd ; else echo ; fi"
-    when: ansible_os_family == 'RedHat'
+    when: init_system.stdout == 'sysvinit'
 
-# Ubuntu 14.04
   - name: stop ceph osds on ubuntu
     shell: |
       for id in $(ls /var/lib/ceph/osd/ |grep -oh '[0-9]*'); do
         initctl stop ceph-osd cluster={{ cluster }} id=$id
       done
     failed_when: false
-    when: ansible_distribution == 'Ubuntu'
+    when: init_system.stdout == 'upstart'
     with_items: "{{ osd_ids.stdout_lines }}"
 
   - name: see if ceph-disk-created data partitions are present
       name: ceph.target
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: ansible_service_mgr == 'systemd'
 
   - name: stop ceph mons with systemd
     service:
       name: ceph-mon@{{ ansible_hostname }}
       state: stopped
       enabled: no
-    when:
-      - ansible_os_family == 'RedHat'
-      - systemd_unit_files.stdout != "0"
+    when: init_system.stdout == 'systemd'
 
   - name: stop ceph mons
     shell: "service ceph status mon ; if [ $? == 0 ] ; then service ceph stop mon ; else echo ; fi"
-    when: ansible_os_family == 'RedHat'
+    when: init_system.stdout == 'sysvinit'
 
   - name: stop ceph mons on ubuntu
     command: initctl stop ceph-mon cluster={{ cluster }} id={{ ansible_hostname }}
     failed_when: false
-    when: ansible_distribution == 'Ubuntu'
+    when: init_system.stdout == 'upstart'
 
   - name: remove monitor store and bootstrap keys
     file:
     rbdmirror_group_name: rbd-mirrors
     nfs_group_name:       nfss
 
-# When set to true both groups of packages are purged.
-# This can cause problem with qemu-kvm
+    # When set to true both groups of packages are purged.
+    # This can cause problem with qemu-kvm
     purge_all_packages: true
 
     ceph_packages:
      path: /var/log/ceph
      state: absent
 
-  - name: remove from SysV
+  - name: remove from sysv
     shell: "update-rc.d -f ceph remove"
-    when: ansible_distribution == 'Ubuntu'
+    when: init_system.stdout == 'sysvinit'
 
-  - name: remove Upstart and SysV files
+  - name: remove upstart and sysv files
     shell: "find /etc -name '*ceph*' -delete"
-    when: ansible_distribution == 'Ubuntu'
+    when: init_system.stdout == 'upstart'
 
-  - name: remove Upstart and apt logs and cache
+  - name: remove upstart and apt logs and cache
     shell: "find /var -name '*ceph*' -delete"
     when: ansible_distribution == 'Ubuntu'
 
     command: dnf clean all
     when: ansible_pkg_mgr == 'dnf'
 
-  - name: purge RPM cache in /tmp
+  - name: purge rpm cache in /tmp
     file:
       path: /tmp/rh-storage-repo
       state: absent