c1c465c7d1ca28430ba679283bd2a932df0dd0f7
[stor4nfv.git] / ci / ansible / roles / cleaner / tasks / main.yml
1 ---
2 - name: remove golang tarball
3   file:
4     path: "/opt/{{ golang_tarball }}"
5     state: absent
6     force: yes
7   ignore_errors: yes
8
9 - name: kill etcd daemon service
10   shell: killall etcd
11   ignore_errors: yes
12   when: db_driver == "etcd" and container_enabled == false
13
14 - name: kill etcd containerized service
15   docker:
16     image: quay.io/coreos/etcd:latest
17     state: stopped
18   when: container_enabled == true
19
20 - name: remove etcd service data
21   file:
22     path: "{{ etcd_dir }}"
23     state: absent
24     force: yes
25   ignore_errors: yes
26   when: db_driver == "etcd"
27
28 - name: remove etcd tarball
29   file:
30     path: "/opt/{{ etcd_tarball }}"
31     state: absent
32     force: yes
33   ignore_errors: yes
34   when: db_driver == "etcd"
35
36 - name: kill osdslet daemon service
37   shell: killall osdslet
38   ignore_errors: yes
39   when: container_enabled == false
40
41 - name: kill osdslet containerized service
42   docker:
43     image: opensdsio/opensds-controller:latest
44     state: stopped
45   when: container_enabled == true
46
47 - name: kill osdsdock daemon service
48   shell: killall osdsdock
49   ignore_errors: yes
50   when: container_enabled == false
51
52 - name: kill osdsdock containerized service
53   docker:
54     image: opensdsio/opensds-dock:latest
55     state: stopped
56   when: container_enabled == true
57
58 - name: clean all opensds build files
59   shell: . /etc/profile; make clean
60   args:
61     chdir: "{{ opensds_root_dir }}"
62
63 - name: clean all opensds configuration files
64   file:
65     path: "{{ opensds_config_dir }}"
66     state: absent
67     force: yes
68   ignore_errors: yes
69
70 - name: clean all opensds log files
71   file:
72     path: "{{ opensds_log_dir }}"
73     state: absent
74     force: yes
75   ignore_errors: yes
76
77 - name: check if it existed before cleaning a volume group
78   shell: vgdisplay {{ vg_name }}
79   ignore_errors: yes
80   register: vg_existed
81   when: enabled_backend == "lvm"
82
83 - name: remove a volume group if lvm backend specified
84   shell: vgremove {{ vg_name }}
85   when: enabled_backend == "lvm" and vg_existed.rc == 0
86
87 - name: check if it existed before cleaning a physical volume
88   shell: pvdisplay {{ pv_device }}
89   ignore_errors: yes
90   register: pv_existed
91   when: enabled_backend == "lvm"
92
93 - name: remove a physical volume if lvm backend specified
94   shell: pvremove {{ pv_device }}
95   when: enabled_backend == "lvm" and pv_existed.rc == 0
96
97 - name: stop cinder-standalone service
98   shell: docker-compose down
99   become: true
100   args:
101     chdir: "{{ cinder_data_dir }}/cinder/contrib/block-box"
102   when: enabled_backend == "cinder"
103
104 - name: clean the volume group of cinder
105   shell:
106     _raw_params: |
107
108       # _clean_lvm_volume_group removes all default LVM volumes
109       #
110       # Usage: _clean_lvm_volume_group $vg
111       function _clean_lvm_volume_group {
112           local vg=$1
113
114           # Clean out existing volumes
115           sudo lvremove -f $vg
116       }
117
118       # _remove_lvm_volume_group removes the volume group
119       #
120       # Usage: _remove_lvm_volume_group $vg
121       function _remove_lvm_volume_group {
122           local vg=$1
123
124           # Remove the volume group
125           sudo vgremove -f $vg
126       }
127
128       # _clean_lvm_backing_file() removes the backing file of the
129       # volume group
130       #
131       # Usage: _clean_lvm_backing_file() $backing_file
132       function _clean_lvm_backing_file {
133           local backing_file=$1
134
135           # If the backing physical device is a loop device, it was probably setup by DevStack
136           if [[ -n "$backing_file" ]] && [[ -e "$backing_file" ]]; then
137               local vg_dev
138               vg_dev=$(sudo losetup -j $backing_file | awk -F':' '/'.img'/ { print $1}')
139               if [[ -n "$vg_dev" ]]; then
140                   sudo losetup -d $vg_dev
141               fi
142               rm -f $backing_file
143           fi
144       }
145
146       # clean_lvm_volume_group() cleans up the volume group and removes the
147       # backing file
148       #
149       # Usage: clean_lvm_volume_group $vg
150       function clean_lvm_volume_group {
151           local vg=$1
152
153           _clean_lvm_volume_group $vg
154           _remove_lvm_volume_group $vg
155           # if there is no logical volume left, it's safe to attempt a cleanup
156           # of the backing file
157           if [[ -z "$(sudo lvs --noheadings -o lv_name $vg 2>/dev/null)" ]]; then
158               _clean_lvm_backing_file {{ cinder_data_dir }}/${vg}.img
159           fi
160       }
161
162       clean_lvm_volume_group {{cinder_volume_group}}
163
164   args:
165     executable: /bin/bash
166   become: true
167   when: enabled_backend == "cinder"