2019-06-20 17:59:25 +08:00
|
|
|
---
|
|
|
|
# This playbook removes the Ceph MDS from your cluster.
|
|
|
|
#
|
|
|
|
# Use it like this:
|
|
|
|
# ansible-playbook shrink-mds.yml -e mds_to_kill=ceph-mds01
|
|
|
|
# Prompts for confirmation to shrink, defaults to no and
|
|
|
|
# doesn't shrink the cluster. yes shrinks the cluster.
|
|
|
|
#
|
|
|
|
# ansible-playbook -e ireallymeanit=yes|no shrink-mds.yml
|
|
|
|
# Overrides the prompt using -e option. Can be used in
|
|
|
|
# automation scripts to avoid interactive prompt.
|
|
|
|
- name: gather facts and check the init system
|
|
|
|
hosts:
|
|
|
|
- "{{ mon_group_name | default('mons') }}"
|
|
|
|
- "{{ mds_group_name | default('mdss') }}"
|
|
|
|
become: true
|
|
|
|
tasks:
|
|
|
|
- debug:
|
|
|
|
msg: gather facts on all Ceph hosts for following reference
|
2020-01-08 22:02:24 +08:00
|
|
|
- import_role:
|
|
|
|
name: ceph-defaults
|
|
|
|
- import_role:
|
|
|
|
name: ceph-facts
|
2020-01-08 23:10:17 +08:00
|
|
|
tasks_from: container_binary
|
2019-06-20 17:59:25 +08:00
|
|
|
|
|
|
|
- name: perform checks, remove mds and print cluster health
|
2020-02-26 23:20:05 +08:00
|
|
|
hosts: "{{ groups[mon_group_name][0] }}"
|
2019-06-20 17:59:25 +08:00
|
|
|
become: true
|
|
|
|
vars_prompt:
|
|
|
|
- name: ireallymeanit
|
|
|
|
prompt: Are you sure you want to shrink the cluster?
|
|
|
|
default: 'no'
|
|
|
|
private: no
|
|
|
|
pre_tasks:
|
|
|
|
- import_role:
|
|
|
|
name: ceph-defaults
|
|
|
|
|
|
|
|
- name: exit playbook, if no mds was given
|
|
|
|
when: mds_to_kill is not defined
|
|
|
|
fail:
|
|
|
|
msg: >
|
|
|
|
mds_to_kill must be declared.
|
|
|
|
Exiting shrink-cluster playbook, no MDS was removed. On the command
|
|
|
|
line when invoking the playbook, you can use
|
|
|
|
"-e mds_to_kill=ceph-mds1" argument. You can only remove a single
|
|
|
|
MDS each time the playbook runs."
|
|
|
|
|
|
|
|
- name: exit playbook, if the mds is not part of the inventory
|
|
|
|
when: mds_to_kill not in groups[mds_group_name]
|
|
|
|
fail:
|
|
|
|
msg: "It seems that the host given is not part of your inventory,
|
|
|
|
please make sure it is."
|
|
|
|
|
|
|
|
- name: exit playbook, if user did not mean to shrink cluster
|
|
|
|
when: ireallymeanit != 'yes'
|
|
|
|
fail:
|
|
|
|
msg: "Exiting shrink-mds playbook, no mds 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"
|
|
|
|
|
|
|
|
- name: set_fact container_exec_cmd for mon0
|
|
|
|
set_fact:
|
2020-02-26 23:20:05 +08:00
|
|
|
container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ ansible_hostname }}"
|
2019-06-20 17:59:25 +08:00
|
|
|
when: containerized_deployment | bool
|
|
|
|
|
|
|
|
- name: exit playbook, if can not connect to the cluster
|
2019-07-03 16:45:46 +08:00
|
|
|
command: "{{ container_exec_cmd | default('') }} timeout 5 ceph --cluster {{ cluster }} health"
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|
2019-06-20 17:59:25 +08:00
|
|
|
register: ceph_health
|
|
|
|
until: ceph_health is succeeded
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
|
|
|
|
- name: set_fact mds_to_kill_hostname
|
|
|
|
set_fact:
|
|
|
|
mds_to_kill_hostname: "{{ hostvars[mds_to_kill]['ansible_hostname'] }}"
|
|
|
|
|
|
|
|
tasks:
|
2019-07-03 16:45:46 +08:00
|
|
|
# get rid of this as soon as "systemctl stop ceph-msd@$HOSTNAME" also
|
|
|
|
# removes the MDS from the FS map.
|
2020-08-19 02:35:17 +08:00
|
|
|
- name: exit mds when containerized deployment
|
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph tell mds.{{ mds_to_kill_hostname }} exit"
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|
2019-07-03 16:45:46 +08:00
|
|
|
when: containerized_deployment | bool
|
|
|
|
|
2020-01-03 22:56:43 +08:00
|
|
|
- name: get ceph status
|
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} -s -f json"
|
|
|
|
register: ceph_status
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|
2020-01-03 22:56:43 +08:00
|
|
|
|
|
|
|
- name: set_fact current_max_mds
|
|
|
|
set_fact:
|
|
|
|
current_max_mds: "{{ (ceph_status.stdout | from_json)['fsmap']['max'] }}"
|
|
|
|
|
|
|
|
- name: fail if removing that mds node wouldn't satisfy max_mds anymore
|
|
|
|
fail:
|
|
|
|
msg: "Can't remove more mds as it won't satisfy current max_mds setting"
|
|
|
|
when:
|
|
|
|
- ((((ceph_status.stdout | from_json)['fsmap']['up'] | int) + ((ceph_status.stdout | from_json)['fsmap']['up:standby'] | int)) - 1) < current_max_mds | int
|
|
|
|
- (ceph_status.stdout | from_json)['fsmap']['up'] | int > 1
|
|
|
|
|
2019-07-03 16:45:46 +08:00
|
|
|
- name: stop mds service and verify it
|
|
|
|
block:
|
|
|
|
- name: stop mds service
|
|
|
|
service:
|
|
|
|
name: ceph-mds@{{ mds_to_kill_hostname }}
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
delegate_to: "{{ mds_to_kill }}"
|
|
|
|
failed_when: false
|
|
|
|
|
|
|
|
- name: ensure that the mds is stopped
|
2020-11-18 17:13:45 +08:00
|
|
|
command: "systemctl is-active ceph-mds@{{ mds_to_kill_hostname }}" # noqa 303
|
2019-07-03 16:45:46 +08:00
|
|
|
register: mds_to_kill_status
|
|
|
|
failed_when: mds_to_kill_status.rc == 0
|
|
|
|
delegate_to: "{{ mds_to_kill }}"
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
|
|
|
|
- name: fail if the mds is reported as active or standby
|
|
|
|
block:
|
2020-01-03 22:56:43 +08:00
|
|
|
- name: get new ceph status
|
2019-07-03 16:45:46 +08:00
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} -s -f json"
|
|
|
|
register: ceph_status
|
|
|
|
|
|
|
|
- name: get active mds nodes list
|
|
|
|
set_fact:
|
|
|
|
active_mdss: "{{ active_mdss | default([]) + [item.name] }}"
|
|
|
|
with_items: "{{ (ceph_status.stdout | from_json)['fsmap']['by_rank'] }}"
|
|
|
|
|
|
|
|
- name: get ceph fs dump status
|
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} fs dump -f json"
|
|
|
|
register: ceph_fs_status
|
|
|
|
|
|
|
|
- name: create a list of standby mdss
|
|
|
|
set_fact:
|
|
|
|
standby_mdss: (ceph_fs_status.stdout | from_json)['standbys'] | map(attribute='name') | list
|
|
|
|
|
|
|
|
- name: fail if mds just killed is being reported as active or standby
|
|
|
|
fail:
|
|
|
|
msg: "mds node {{ mds_to_kill }} still up and running."
|
|
|
|
when:
|
|
|
|
- (mds_to_kill in active_mdss | default([])) or
|
|
|
|
(mds_to_kill in standby_mdss | default([]))
|
|
|
|
|
2020-01-03 23:02:48 +08:00
|
|
|
- name: delete the filesystem when killing last mds
|
2020-10-23 23:46:30 +08:00
|
|
|
ceph_fs:
|
|
|
|
name: "{{ cephfs }}"
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
state: absent
|
2020-01-15 14:17:08 +08:00
|
|
|
when:
|
|
|
|
- (ceph_status.stdout | from_json)['fsmap']['up'] | int == 0
|
|
|
|
- (ceph_status.stdout | from_json)['fsmap']['up:standby'] | int == 0
|
2020-10-23 23:46:30 +08:00
|
|
|
environment:
|
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
|
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
2019-06-20 17:59:25 +08:00
|
|
|
|
|
|
|
- name: purge mds store
|
|
|
|
file:
|
|
|
|
path: /var/lib/ceph/mds/{{ cluster }}-{{ mds_to_kill_hostname }}
|
|
|
|
state: absent
|
|
|
|
delegate_to: "{{ mds_to_kill }}"
|
|
|
|
|
|
|
|
post_tasks:
|
|
|
|
- name: show ceph health
|
2019-07-03 16:45:46 +08:00
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} -s"
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|