purge: fix ubuntu purge when not using systemd

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>
pull/1254/head
Sébastien Han 2017-01-27 11:33:37 +01:00
parent 0e2e270ab2
commit e371bd591c
1 changed files with 38 additions and 69 deletions

View File

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