2019-06-26 13:59:50 +08:00
|
|
|
---
|
|
|
|
# This playbook shrinks the Ceph RGW from your cluster
|
|
|
|
#
|
|
|
|
# Use it like this:
|
|
|
|
# ansible-playbook shrink-rgw.yml -e rgw_to_kill=ceph-rgw01
|
|
|
|
# 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-rgw.yml
|
|
|
|
# Overrides the prompt using -e option. Can be used in
|
|
|
|
# automation scripts to avoid interactive prompt.
|
|
|
|
|
|
|
|
|
2019-09-22 15:10:25 +08:00
|
|
|
- name: confirm whether user really meant to remove rgw from the ceph cluster
|
2019-06-26 13:59:50 +08:00
|
|
|
hosts: localhost
|
2020-01-10 00:48:13 +08:00
|
|
|
become: false
|
|
|
|
gather_facts: false
|
2019-06-26 13:59:50 +08:00
|
|
|
vars_prompt:
|
|
|
|
- name: ireallymeanit
|
|
|
|
prompt: Are you sure you want to shrink the cluster?
|
|
|
|
default: 'no'
|
|
|
|
private: no
|
2020-01-10 00:48:13 +08:00
|
|
|
tasks:
|
2019-06-26 13:59:50 +08:00
|
|
|
- name: exit playbook, if no rgw was given
|
2020-01-10 00:48:13 +08:00
|
|
|
when: rgw_to_kill is not defined or rgw_to_kill | length == 0
|
2019-06-26 13:59:50 +08:00
|
|
|
fail:
|
|
|
|
msg: >
|
|
|
|
rgw_to_kill must be declared.
|
|
|
|
Exiting shrink-cluster playbook, no RGW was removed. On the command
|
|
|
|
line when invoking the playbook, you can use
|
2020-01-10 00:48:13 +08:00
|
|
|
"-e rgw_to_kill=ceph.rgw0 argument". You can only remove a single
|
2019-06-26 13:59:50 +08:00
|
|
|
RGW each time the playbook runs.
|
|
|
|
|
|
|
|
- name: exit playbook, if user did not mean to shrink cluster
|
|
|
|
when: ireallymeanit != 'yes'
|
|
|
|
fail:
|
|
|
|
msg: >
|
|
|
|
Exiting shrink-mon playbook, no monitor was removed. To shrink the
|
|
|
|
cluster, either say 'yes' on the prompt or use
|
|
|
|
'-e ireallymeanit=yes' on the command line when invoking the playbook
|
|
|
|
|
2020-01-10 00:48:13 +08:00
|
|
|
- name: gather facts and mons and rgws
|
|
|
|
hosts:
|
|
|
|
- "{{ mon_group_name | default('mons') }}[0]"
|
|
|
|
- "{{ rgw_group_name | default('rgws') }}"
|
|
|
|
become: true
|
|
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
|
|
- setup:
|
2020-06-30 22:13:42 +08:00
|
|
|
gather_subset:
|
|
|
|
- 'all'
|
|
|
|
- '!facter'
|
|
|
|
- '!ohai'
|
2020-01-10 00:48:13 +08:00
|
|
|
|
|
|
|
- hosts: mons[0]
|
|
|
|
become: true
|
|
|
|
gather_facts: false
|
|
|
|
pre_tasks:
|
|
|
|
- import_role:
|
|
|
|
name: ceph-defaults
|
|
|
|
|
|
|
|
- import_role:
|
|
|
|
name: ceph-facts
|
|
|
|
tasks_from: container_binary
|
|
|
|
|
2019-06-26 13:59:50 +08:00
|
|
|
- name: set_fact container_exec_cmd for mon0
|
|
|
|
set_fact:
|
2020-01-10 00:48:13 +08:00
|
|
|
container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ ansible_hostname }}"
|
|
|
|
when: containerized_deployment | bool
|
2019-06-26 13:59:50 +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
|
|
|
|
until: ceph_health is succeeded
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
|
2020-01-10 00:48:13 +08:00
|
|
|
- name: get rgw instances
|
2020-10-27 05:49:47 +08:00
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} service dump -f json"
|
2020-01-10 00:48:13 +08:00
|
|
|
register: rgw_instances
|
2019-06-26 13:59:50 +08:00
|
|
|
|
2020-01-10 00:48:13 +08:00
|
|
|
|
|
|
|
- name: exit playbook, if the rgw_to_kill doesn't exist
|
2020-10-27 05:49:47 +08:00
|
|
|
when: rgw_to_kill not in (rgw_instances.stdout | from_json).services.rgw.daemons.keys() | list
|
2020-01-10 00:48:13 +08:00
|
|
|
fail:
|
|
|
|
msg: >
|
|
|
|
It seems that the rgw instance given is not part of the ceph cluster. Please
|
|
|
|
make sure it is.
|
|
|
|
The rgw instance format is $(hostname}.rgw$(instance number).
|
|
|
|
tasks:
|
|
|
|
- name: get rgw host running the rgw instance to kill
|
|
|
|
set_fact:
|
|
|
|
rgw_host: '{{ item }}'
|
|
|
|
with_items: '{{ groups[rgw_group_name] }}'
|
|
|
|
when: hostvars[item]['ansible_hostname'] == rgw_to_kill.split('.')[0]
|
|
|
|
|
|
|
|
- name: stop rgw service
|
|
|
|
service:
|
|
|
|
name: ceph-radosgw@rgw.{{ rgw_to_kill }}
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
delegate_to: "{{ rgw_host }}"
|
|
|
|
failed_when: false
|
|
|
|
|
|
|
|
- name: ensure that the rgw is stopped
|
|
|
|
command: "systemctl is-active ceph-radosgw@rgw.{{ rgw_to_kill }}"
|
|
|
|
register: rgw_to_kill_status
|
|
|
|
failed_when: rgw_to_kill_status.rc == 0
|
|
|
|
delegate_to: "{{ rgw_host }}"
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
2019-06-26 13:59:50 +08:00
|
|
|
|
|
|
|
- name: exit if rgw_to_kill is reported in ceph status
|
2020-10-27 05:49:47 +08:00
|
|
|
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} service dump -f json"
|
2019-06-26 13:59:50 +08:00
|
|
|
register: ceph_status
|
|
|
|
failed_when:
|
2020-10-27 05:49:47 +08:00
|
|
|
- (ceph_status.stdout | from_json).services.rgw is defined
|
|
|
|
- rgw_to_kill in (ceph_status.stdout | from_json).services.rgw.daemons.keys() | list
|
2019-06-26 13:59:50 +08:00
|
|
|
until:
|
2020-10-27 05:49:47 +08:00
|
|
|
- (ceph_status.stdout | from_json).services.rgw is defined
|
|
|
|
- rgw_to_kill not in (ceph_status.stdout | from_json).services.rgw.daemons.keys() | list
|
2019-06-26 13:59:50 +08:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
|
|
|
|
- name: purge directories related to rgw
|
|
|
|
file:
|
2020-01-10 00:48:13 +08:00
|
|
|
path: /var/lib/ceph/radosgw/{{ cluster }}-rgw.{{ rgw_to_kill }}
|
2019-06-26 13:59:50 +08:00
|
|
|
state: absent
|
2020-01-10 00:48:13 +08:00
|
|
|
delegate_to: "{{ rgw_host }}"
|
2019-06-26 13:59:50 +08:00
|
|
|
post_tasks:
|
|
|
|
- name: show ceph health
|
|
|
|
command: "{{ container_exec_cmd | default('')}} ceph --cluster {{ cluster }} -s"
|