forked from ceph/cephadm-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cephadm-purge-cluster.yml
171 lines (142 loc) · 4.81 KB
/
cephadm-purge-cluster.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
# Copyright Red Hat
# SPDX-License-Identifier: Apache-2.0
#
# This playbook purges a Ceph cluster managed with cephadm
#
# You must define a group [admin] in your inventory with a node where
# the admin keyring is present at /etc/ceph/ceph.client.admin.keyring
#
# Usage:
#
# ansible-playbook -i <inventory host file> cephadm-purge-cluster.yml -e fsid=<your fsid> -e infra_pkgs_purge=<infra packages to uninstall>
- name: check local prerequisites are in place
hosts: all
gather_facts: false
become: true
any_errors_fatal: true
tasks:
- run_once: true
delegate_to: localhost
block:
- name: fail if fsid was not provided
fail:
msg: |
You must provide the cluster fsid to be purged.
e.g. ansible-playbook -i <inventory host file> cephadm-purge-cluster.yml -e fsid=<your fsid>
when: fsid is undefined
- name: fail if admin group doesn't exist or is empty
fail:
msg: |
You must define a group [admin] in your inventory and add a node where
admin keyring is present at /etc/ceph/ceph.client.admin.keyring
when: "'admin' not in groups or groups['admin'] | length < 1"
- name: check keyring is present on the admin host
hosts: admin[0]
gather_facts: false
any_errors_fatal: true
tasks:
- name: check /etc/ceph/ceph.client.admin.keyring
stat:
path: /etc/ceph/ceph.client.admin.keyring
register: admin_keyring_stat
- name: fail if /etc/ceph/ceph.client.admin.keyring is not present
fail:
msg: >
You must have /etc/ceph/ceph.client.admin.keyring present on {{ inventory_hostname }}
when: not admin_keyring_stat.stat.exists | bool
- name: check cluster hosts have cephadm and the required fsid {{ fsid }}
hosts: all,!{{ client_group }}
gather_facts: false
become: true
any_errors_fatal: true
tasks:
- name: import_role ceph_defaults
import_role:
name: ceph_defaults
- name: check cephadm binary is available
command: which cephadm
register: cephadm_exists
changed_when: false
failed_when: false
- name: fail if cephadm is not available
fail:
msg: |
The cephadm binary is missing on {{ inventory_hostname }}. To purge the cluster you must have cephadm installed
on ALL ceph hosts. Install manually or use the preflight playbook.
when:
- cephadm_exists.rc
- name: check fsid directory given is valid across the cluster
stat:
path: /var/lib/ceph/{{ fsid }}
register: fsid_exists
- name: fail if the fsid directory is missing
fail:
msg: |
The fsid directory '/var/lib/ceph/{{ fsid }}' can not be found on {{ inventory_hostname }}
Is the fsid correct?
when:
- not fsid_exists.stat.exists | bool
- name: confirm whether user really wants to purge the cluster
hosts: all
gather_facts: false
become: false
vars_prompt:
- name: ireallymeanit
prompt: |
Are you sure you want to purge the cluster with fsid={{ fsid }} ?
default: 'no'
private: no
tasks:
- name: exit playbook, if user did not mean to purge cluster
run_once: true
delegate_to: localhost
fail:
msg: |
Exiting cephadm-purge-cluster playbook, cluster was NOT purged.
To purge the cluster, either say 'yes' at the prompt or use `-e ireallymeanit=yes`
on the command line when invoking the playbook
when: ireallymeanit != 'yes'
- name: disable cephadm operations
hosts: "admin[0]"
become: true
gather_facts: false
tasks:
- name: disable cephadm
command: "cephadm shell --fsid {{ fsid }} -- ceph mgr module disable cephadm"
changed_when: false
- name: Purge ceph daemons from all hosts in the cluster
hosts: all,!{{ client_group }}
become: true
gather_facts: false
any_errors_fatal: true
tasks:
- name: import_role ceph_defaults
import_role:
name: ceph_defaults
- name: purge ceph daemons
command: "cephadm rm-cluster --force --zap-osds --fsid {{ fsid }}"
changed_when: false
- name: remove ceph packages
hosts: all
become: true
gather_facts: false
any_errors_fatal: true
tasks:
- name: import_role ceph_defaults
import_role:
name: ceph_defaults
- name: remove ceph packages on ceph nodes
package:
name: "{{ ceph_pkgs | union(infra_pkgs | intersect(infra_pkgs_purge | default([]))) }}"
state: absent
register: result
until: result is succeeded
when: group_names != [client_group]
- name: remove ceph packages on client nodes
package:
name: ceph-common
state: absent
register: result
until: result is succeeded
when: group_names == [client_group]