forked from ceph/cephadm-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cephadm-purge-cluster.yml
161 lines (133 loc) · 4.48 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
---
# 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>
- name: check local prerequisites are in place
hosts: localhost
gather_facts: false
become: true
any_errors_fatal: true
tasks:
- 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/admin.client.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.admin.client.keyring
stat:
path: /etc/ceph/ceph.client.admin.keyring
register: admin_keyring_stat
- name: fail if /etc/ceph/admin.client.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
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
when: group_names != [client_group]
- 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:
- group_names != [client_group]
- cephadm_exists.rc
- name: check fsid directory given is valid across the cluster
stat:
path: /var/lib/ceph/{{ fsid }}
register: fsid_exists
when: group_names != [client_group]
- 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:
- group_names != [client_group]
- not fsid_exists.stat.exists | bool
- name: confirm whether user really wants to purge the cluster
hosts: localhost
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
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
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 }}"
when: group_names != [client_group]
- 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
package:
name: "{{ 'ceph-common' if group_names == [client_group] else ceph_pkgs | unique }}"
state: absent
register: result
until: result is succeeded