2019-06-12 12:46:00 +08:00
|
|
|
---
|
|
|
|
# This playbook shrinks the Ceph manager from your cluster
|
|
|
|
#
|
|
|
|
# Use it like this:
|
|
|
|
# ansible-playbook shrink-mgr.yml -e mgr_to_kill=ceph-mgr1
|
|
|
|
# Prompts for confirmation to shrink, defaults to no and
|
|
|
|
# doesn't shrink the cluster and yes shrinks the cluster.
|
|
|
|
#
|
|
|
|
# ansible-playbook -e ireallymeanit=yes|no shrink-mgr.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') }}"
|
|
|
|
- "{{ mgr_group_name | default('mgrs') }}"
|
|
|
|
become: true
|
|
|
|
tasks:
|
|
|
|
- debug:
|
|
|
|
msg: gather facts on all Ceph hosts for following reference
|
|
|
|
|
|
|
|
- name: confirm if user really meant to remove manager from the ceph cluster
|
2024-02-13 07:48:13 +08:00
|
|
|
hosts: mons[0]
|
2019-06-12 12:46:00 +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
|
|
|
|
|
|
|
|
- import_role:
|
|
|
|
name: ceph-facts
|
2020-02-26 23:20:05 +08:00
|
|
|
tasks_from: container_binary
|
2019-06-12 12:46:00 +08:00
|
|
|
|
|
|
|
- name: set_fact container_exec_cmd
|
|
|
|
when: containerized_deployment | bool
|
|
|
|
set_fact:
|
2021-03-03 22:43:50 +08:00
|
|
|
container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ ansible_facts['hostname'] }}"
|
2019-06-12 12:46:00 +08:00
|
|
|
|
|
|
|
- name: exit playbook, if can not connect to the cluster
|
|
|
|
command: "{{ container_exec_cmd | default('') }} timeout 5 ceph --cluster {{ cluster }} health"
|
|
|
|
register: ceph_health
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|
2019-07-25 19:32:32 +08:00
|
|
|
until: ceph_health is succeeded
|
2019-06-12 12:46:00 +08:00
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
|
|
|
|
- name: get total number of mgrs in cluster
|
|
|
|
block:
|
|
|
|
- name: save mgr dump output
|
2020-10-02 19:05:01 +08:00
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} mgr dump -f json"
|
2019-06-12 12:46:00 +08:00
|
|
|
register: mgr_dump
|
|
|
|
|
2020-02-27 00:16:56 +08:00
|
|
|
- name: get active and standbys mgr list
|
2019-06-12 12:46:00 +08:00
|
|
|
set_fact:
|
|
|
|
active_mgr: "{{ [mgr_dump.stdout | from_json] | map(attribute='active_name') | list }}"
|
2020-02-27 00:16:56 +08:00
|
|
|
standbys_mgr: "{{ (mgr_dump.stdout | from_json)['standbys'] | map(attribute='name') | list }}"
|
2019-06-12 12:46:00 +08:00
|
|
|
|
|
|
|
- name: exit playbook, if there's no standby manager
|
|
|
|
fail:
|
|
|
|
msg: "You are about to shrink the only manager present in the cluster."
|
2020-02-27 00:16:56 +08:00
|
|
|
when: standbys_mgr | length | int < 1
|
2019-06-12 12:46:00 +08:00
|
|
|
|
|
|
|
- name: exit playbook, if no manager was given
|
|
|
|
fail:
|
|
|
|
msg: "mgr_to_kill must be declared
|
|
|
|
Exiting shrink-cluster playbook, no manager was removed.
|
|
|
|
On the command line when invoking the playbook, you can use
|
|
|
|
-e mgr_to_kill=ceph-mgr01 argument. You can only remove a single
|
|
|
|
manager each time the playbook runs."
|
|
|
|
when: mgr_to_kill is not defined
|
|
|
|
|
|
|
|
- name: exit playbook, if user did not mean to shrink cluster
|
|
|
|
fail:
|
|
|
|
msg: "Exiting shrink-mgr playbook, no manager 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"
|
|
|
|
when: ireallymeanit != 'yes'
|
|
|
|
|
|
|
|
- name: set_fact mgr_to_kill_hostname
|
|
|
|
set_fact:
|
2021-03-03 22:43:50 +08:00
|
|
|
mgr_to_kill_hostname: "{{ hostvars[mgr_to_kill]['ansible_facts']['hostname'] }}"
|
2019-06-12 12:46:00 +08:00
|
|
|
|
2021-06-29 02:16:03 +08:00
|
|
|
- name: exit playbook, if the selected manager is not present in the cluster
|
|
|
|
fail:
|
|
|
|
msg: "It seems that the host given is not present in the cluster."
|
|
|
|
when:
|
|
|
|
- mgr_to_kill_hostname not in active_mgr
|
|
|
|
- mgr_to_kill_hostname not in standbys_mgr
|
|
|
|
|
2019-06-12 12:46:00 +08:00
|
|
|
tasks:
|
|
|
|
- name: stop manager services and verify it
|
|
|
|
block:
|
|
|
|
- name: stop manager service
|
|
|
|
service:
|
|
|
|
name: ceph-mgr@{{ mgr_to_kill_hostname }}
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
delegate_to: "{{ mgr_to_kill }}"
|
|
|
|
failed_when: false
|
|
|
|
|
2020-02-27 00:16:56 +08:00
|
|
|
- name: ensure that the mgr is stopped
|
2020-11-18 17:13:45 +08:00
|
|
|
command: "systemctl is-active ceph-mgr@{{ mgr_to_kill_hostname }}" # noqa 303
|
2019-06-12 12:46:00 +08:00
|
|
|
register: mgr_to_kill_status
|
|
|
|
failed_when: mgr_to_kill_status.rc == 0
|
|
|
|
delegate_to: "{{ mgr_to_kill }}"
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
|
2020-02-27 00:16:56 +08:00
|
|
|
- name: fail if the mgr is reported in ceph mgr dump
|
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} mgr dump -f json"
|
|
|
|
register: mgr_dump
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|
2020-02-27 00:16:56 +08:00
|
|
|
failed_when: mgr_to_kill_hostname in (([mgr_dump.stdout | from_json] | map(attribute='active_name') | list) + (mgr_dump.stdout | from_json)['standbys'] | map(attribute='name') | list)
|
|
|
|
until: mgr_to_kill_hostname not in (([mgr_dump.stdout | from_json] | map(attribute='active_name') | list) + (mgr_dump.stdout | from_json)['standbys'] | map(attribute='name') | list)
|
|
|
|
retries: 12
|
|
|
|
delay: 10
|
2019-06-12 12:46:00 +08:00
|
|
|
|
|
|
|
- name: purge manager store
|
|
|
|
file:
|
|
|
|
path: /var/lib/ceph/mgr/{{ cluster }}-{{ mgr_to_kill_hostname }}
|
|
|
|
state: absent
|
|
|
|
delegate_to: "{{ mgr_to_kill }}"
|
|
|
|
|
|
|
|
post_tasks:
|
|
|
|
- name: show ceph health
|
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} -s"
|
2024-02-13 07:48:13 +08:00
|
|
|
changed_when: false
|