2016-08-11 23:20:07 +08:00
|
|
|
---
|
|
|
|
# This playbook shrinks the Ceph monitors from your cluster
|
2017-08-31 06:07:28 +08:00
|
|
|
# It can remove a Ceph of monitor from the cluster and ALL ITS DATA
|
2016-08-11 23:20:07 +08:00
|
|
|
#
|
|
|
|
# Use it like this:
|
2017-08-31 06:07:28 +08:00
|
|
|
# ansible-playbook shrink-mon.yml -e mon_to_kill=ceph-mon01
|
2016-08-11 23:20:07 +08:00
|
|
|
# Prompts for confirmation to shrink, defaults to no and
|
|
|
|
# doesn't shrink the cluster. yes shrinks the cluster.
|
|
|
|
#
|
2017-10-27 17:59:22 +08:00
|
|
|
# ansible-playbook -e ireallymeanit=yes|no shrink-mon.yml
|
2016-08-11 23:20:07 +08:00
|
|
|
# Overrides the prompt using -e option. Can be used in
|
|
|
|
# automation scripts to avoid interactive prompt.
|
|
|
|
|
|
|
|
|
2017-08-31 06:07:28 +08:00
|
|
|
- name: gather facts and check the init system
|
|
|
|
|
2019-04-01 23:46:15 +08:00
|
|
|
hosts: "{{ mon_group_name|default('mons') }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
become: true
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- debug: msg="gather facts on all Ceph hosts for following reference"
|
|
|
|
|
|
|
|
- name: confirm whether user really meant to remove monitor from the ceph cluster
|
2019-04-01 23:46:15 +08:00
|
|
|
hosts: localhost
|
2016-08-11 23:20:07 +08:00
|
|
|
become: true
|
|
|
|
vars_prompt:
|
|
|
|
- name: ireallymeanit
|
|
|
|
prompt: Are you sure you want to shrink the cluster?
|
|
|
|
default: 'no'
|
|
|
|
private: no
|
2017-08-31 06:07:28 +08:00
|
|
|
vars:
|
|
|
|
mon_group_name: mons
|
|
|
|
|
2018-10-01 23:43:24 +08:00
|
|
|
tasks:
|
|
|
|
# pre task for following import
|
2017-08-31 06:07:28 +08:00
|
|
|
- name: exit playbook, if only one monitor is present in cluster
|
|
|
|
fail:
|
|
|
|
msg: "You are about to shrink the only monitor present in the cluster.
|
|
|
|
If you really want to do that, please use the purge-cluster playbook."
|
2019-04-01 23:46:15 +08:00
|
|
|
when: groups[mon_group_name] | length | int == 1
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: exit playbook, if no monitor was given
|
|
|
|
fail:
|
|
|
|
msg: "mon_to_kill must be declared
|
|
|
|
Exiting shrink-cluster playbook, no monitor was removed.
|
|
|
|
On the command line when invoking the playbook, you can use
|
|
|
|
-e mon_to_kill=ceph-mon01 argument. You can only remove a single monitor each time the playbook runs."
|
2019-04-01 23:46:15 +08:00
|
|
|
when: mon_to_kill is not defined
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: exit playbook, if the monitor is not part of the inventory
|
|
|
|
fail:
|
|
|
|
msg: "It seems that the host given is not part of your inventory, please make sure it is."
|
2019-04-01 23:46:15 +08:00
|
|
|
when: mon_to_kill not in groups[mon_group_name]
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: exit playbook, if user did not mean to shrink cluster
|
|
|
|
fail:
|
|
|
|
msg: "Exiting shrink-mon playbook, no monitor was removed.
|
|
|
|
To shrink the cluster, either say 'yes' on the prompt or
|
|
|
|
or use `-e ireallymeanit=yes` on the command line when
|
|
|
|
invoking the playbook"
|
2019-04-01 23:46:15 +08:00
|
|
|
when: ireallymeanit != 'yes'
|
2017-08-31 06:07:28 +08:00
|
|
|
|
2018-10-01 23:43:24 +08:00
|
|
|
- import_role:
|
|
|
|
name: ceph-defaults
|
2017-08-31 06:07:28 +08:00
|
|
|
|
2018-12-10 22:46:32 +08:00
|
|
|
- import_role:
|
|
|
|
name: ceph-facts
|
|
|
|
|
2018-10-01 23:43:24 +08:00
|
|
|
# post_tasks for preceding import
|
2017-08-31 06:07:28 +08:00
|
|
|
- name: pick a monitor different than the one we want to remove
|
2017-09-18 23:45:08 +08:00
|
|
|
set_fact:
|
|
|
|
mon_host: "{{ item }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
with_items: "{{ groups[mon_group_name] }}"
|
2019-04-01 23:46:15 +08:00
|
|
|
when: item != mon_to_kill
|
2017-08-31 06:07:28 +08:00
|
|
|
|
2019-05-14 20:51:32 +08:00
|
|
|
- name: "set_fact container_exec_cmd build {{ container_binary }} exec command (containerized)"
|
2017-09-18 23:45:08 +08:00
|
|
|
set_fact:
|
2019-05-14 20:51:32 +08:00
|
|
|
container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ hostvars[mon_host]['ansible_hostname'] }}"
|
2019-05-22 16:02:42 +08:00
|
|
|
when: containerized_deployment | bool
|
2017-09-18 23:45:08 +08:00
|
|
|
|
2017-08-31 06:07:28 +08:00
|
|
|
- name: exit playbook, if can not connect to the cluster
|
2019-05-14 20:51:32 +08:00
|
|
|
command: "{{ container_exec_cmd }} timeout 5 ceph --cluster {{ cluster }} health"
|
2017-08-31 06:07:28 +08:00
|
|
|
register: ceph_health
|
|
|
|
until: ceph_health.stdout.find("HEALTH") > -1
|
|
|
|
delegate_to: "{{ mon_host }}"
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
|
2017-09-18 23:45:08 +08:00
|
|
|
- name: set_fact mon_to_kill_hostname
|
|
|
|
set_fact:
|
2017-08-31 06:07:28 +08:00
|
|
|
mon_to_kill_hostname: "{{ hostvars[mon_to_kill]['ansible_hostname'] }}"
|
|
|
|
|
|
|
|
- name: stop monitor service(s)
|
|
|
|
service:
|
|
|
|
name: ceph-mon@{{ mon_to_kill_hostname }}
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
delegate_to: "{{ mon_to_kill }}"
|
|
|
|
failed_when: false
|
|
|
|
|
|
|
|
- name: purge monitor store
|
|
|
|
file:
|
|
|
|
path: /var/lib/ceph/mon/{{ cluster }}-{{ mon_to_kill_hostname }}
|
|
|
|
state: absent
|
|
|
|
delegate_to: "{{ mon_to_kill }}"
|
|
|
|
|
|
|
|
- name: remove monitor from the quorum
|
2019-05-14 20:51:32 +08:00
|
|
|
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} mon remove {{ mon_to_kill_hostname }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
failed_when: false
|
|
|
|
delegate_to: "{{ mon_host }}"
|
|
|
|
|
|
|
|
# NOTE (leseb): sorry for the 'sleep' command
|
|
|
|
# but it will take a couple of seconds for other monitors
|
|
|
|
# to notice that one member has left.
|
|
|
|
# 'sleep 5' is not that bad and should be sufficient
|
|
|
|
- name: verify the monitor is out of the cluster
|
|
|
|
shell: |
|
2019-05-14 20:51:32 +08:00
|
|
|
{{ container_exec_cmd }} ceph --cluster {{ cluster }} -s -f json | python -c 'import sys, json; print(json.load(sys.stdin)["quorum_names"])'
|
2017-08-31 06:07:28 +08:00
|
|
|
delegate_to: "{{ mon_host }}"
|
2017-09-05 04:13:17 +08:00
|
|
|
failed_when: false
|
2017-08-31 06:07:28 +08:00
|
|
|
register: result
|
2017-09-05 04:13:17 +08:00
|
|
|
until: mon_to_kill_hostname not in result.stdout
|
|
|
|
retries: 2
|
|
|
|
delay: 10
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: please remove the monitor from your ceph configuration file
|
|
|
|
debug:
|
|
|
|
msg: "The monitor has been successfully removed from the cluster.
|
|
|
|
Please remove the monitor entry from the rest of your ceph configuration files, cluster wide."
|
|
|
|
run_once: true
|
2019-04-01 23:46:15 +08:00
|
|
|
when: mon_to_kill_hostname not in result.stdout
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: fail if monitor is still part of the cluster
|
|
|
|
fail:
|
|
|
|
msg: "Monitor appears to still be part of the cluster, please check what happened."
|
|
|
|
run_once: true
|
2019-04-01 23:46:15 +08:00
|
|
|
when: mon_to_kill_hostname in result.stdout
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: show ceph health
|
2019-05-14 20:51:32 +08:00
|
|
|
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} -s"
|
2017-08-31 06:07:28 +08:00
|
|
|
delegate_to: "{{ mon_host }}"
|
|
|
|
|
|
|
|
- name: show ceph mon status
|
2019-05-14 20:51:32 +08:00
|
|
|
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} mon stat"
|
2017-08-31 06:07:28 +08:00
|
|
|
delegate_to: "{{ mon_host }}"
|