2016-08-11 23:20:07 +08:00
|
|
|
---
|
|
|
|
# This playbook shrinks Ceph OSDs.
|
|
|
|
# It can remove any number of OSD(s) from the cluster and ALL THEIR DATA
|
|
|
|
#
|
|
|
|
# Use it like this:
|
2017-08-31 06:07:28 +08:00
|
|
|
# ansible-playbook shrink-osd.yml -e osd_to_kill=0,2,6
|
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.
|
|
|
|
#
|
|
|
|
# ansible-playbook -e ireallymeanit=yes|no shrink-osd.yml
|
|
|
|
# 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
|
|
|
|
|
|
|
|
hosts:
|
|
|
|
- "{{ mon_group_name|default('mons') }}"
|
|
|
|
- "{{ osd_group_name|default('osds') }}"
|
|
|
|
|
|
|
|
become: True
|
|
|
|
tasks:
|
|
|
|
- debug: msg="gather facts on all Ceph hosts for following reference"
|
2016-08-11 23:20:07 +08:00
|
|
|
|
|
|
|
- name: confirm whether user really meant to remove osd(s) from the cluster
|
|
|
|
|
|
|
|
hosts:
|
|
|
|
- localhost
|
|
|
|
|
|
|
|
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
|
|
|
|
osd_group_name: osds
|
|
|
|
|
|
|
|
pre_tasks:
|
|
|
|
- name: exit playbook, if user did not mean to shrink cluster
|
|
|
|
fail:
|
|
|
|
msg: "Exiting shrink-osd playbook, no osd(s) was/were 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: exit playbook, if no osd(s) was/were given
|
|
|
|
fail:
|
|
|
|
msg: "osd_to_kill must be declared
|
2017-09-13 07:05:34 +08:00
|
|
|
Exiting shrink-osd playbook, no OSD(s) was/were removed.
|
2017-08-31 06:07:28 +08:00
|
|
|
On the command line when invoking the playbook, you can use
|
|
|
|
-e osd_to_kill=0,1,2,3 argument."
|
|
|
|
when: osd_to_kill is not defined
|
|
|
|
|
|
|
|
roles:
|
|
|
|
- ceph-defaults
|
2018-12-10 22:46:32 +08:00
|
|
|
- ceph-facts
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
post_tasks:
|
|
|
|
|
2017-09-18 23:45:08 +08:00
|
|
|
- name: set_fact docker_exec_cmd build docker exec command (containerized)
|
|
|
|
set_fact:
|
|
|
|
docker_exec_cmd: "docker exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_hostname'] }}"
|
|
|
|
when: containerized_deployment
|
|
|
|
|
2017-08-31 06:07:28 +08:00
|
|
|
- name: exit playbook, if can not connect to the cluster
|
2017-09-18 23:45:08 +08:00
|
|
|
command: "{{ docker_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: "{{ groups[mon_group_name][0] }}"
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
|
|
|
|
- name: find the host(s) where the osd(s) is/are running on
|
2017-09-18 23:45:08 +08:00
|
|
|
command: "{{ docker_exec_cmd }} ceph --cluster {{ cluster }} osd find {{ item }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
with_items: "{{ osd_to_kill.split(',') }}"
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
|
|
|
register: find_osd_hosts
|
|
|
|
|
2017-09-18 23:45:08 +08:00
|
|
|
- name: set_fact osd_hosts
|
|
|
|
set_fact:
|
2017-09-13 07:05:34 +08:00
|
|
|
osd_hosts: "{{ osd_hosts | default([]) + [ (item.stdout | from_json).crush_location.host ] }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
with_items: "{{ find_osd_hosts.results }}"
|
|
|
|
|
|
|
|
- name: check if ceph admin key exists on the osd nodes
|
|
|
|
stat:
|
|
|
|
path: "/etc/ceph/{{ cluster }}.client.admin.keyring"
|
|
|
|
register: ceph_admin_key
|
|
|
|
with_items: "{{ osd_hosts }}"
|
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
failed_when: false
|
2017-10-07 01:15:26 +08:00
|
|
|
when:
|
|
|
|
- not containerized_deployment
|
2017-08-31 06:07:28 +08:00
|
|
|
|
2017-09-18 23:45:08 +08:00
|
|
|
- name: fail when admin key is not present
|
|
|
|
fail:
|
2017-08-31 06:07:28 +08:00
|
|
|
msg: "The Ceph admin key is not present on the OSD node, please add it and remove it after the playbook is done."
|
|
|
|
with_items: "{{ ceph_admin_key.results }}"
|
|
|
|
when:
|
2017-10-07 01:15:26 +08:00
|
|
|
- not containerized_deployment
|
|
|
|
- item.stat.exists == false
|
2017-08-31 06:07:28 +08:00
|
|
|
|
2017-09-18 23:45:08 +08:00
|
|
|
# NOTE(leseb): using '>' is the only way I could have the command working
|
|
|
|
- name: find osd device based on the id
|
|
|
|
shell: >
|
2019-08-06 02:32:18 +08:00
|
|
|
{{ 'docker run --privileged=true --ulimit nofile=1024:4096 -v /dev:/dev --entrypoint' if containerized_deployment else '' }} /usr/sbin/ceph-disk
|
2019-07-09 15:48:08 +08:00
|
|
|
{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment else '' }}
|
2019-08-06 02:32:18 +08:00
|
|
|
list | awk -v pattern=osd.{{ item.0 }}, '$0 ~ pattern {print $1}'
|
2017-09-18 23:45:08 +08:00
|
|
|
with_together:
|
|
|
|
- "{{ osd_to_kill.split(',') }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
register: osd_to_kill_disks
|
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
|
2018-07-19 21:45:55 +08:00
|
|
|
- name: find osd dedicated devices - container
|
|
|
|
shell: >
|
2019-08-06 02:32:18 +08:00
|
|
|
docker run --privileged=true --ulimit nofile=1024:4096 -v /dev:/dev --entrypoint /usr/sbin/ceph-disk
|
2018-07-19 21:45:55 +08:00
|
|
|
{{ ceph_docker_registry}}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }}
|
2019-08-06 02:32:18 +08:00
|
|
|
list | grep osd.{{ item.0 }}, | grep -Eo '/dev/([hsv]d[a-z]{1,2})[0-9]{1,2}|/dev/nvme[0-9]n[0-9]p[0-9]'
|
2018-07-19 21:45:55 +08:00
|
|
|
with_together:
|
|
|
|
- "{{ osd_to_kill.split(',') }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
register: osd_to_kill_disks_dedicated
|
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
when:
|
|
|
|
- containerized_deployment
|
|
|
|
|
|
|
|
- name: find osd dedicated devices - non container
|
2019-08-06 02:32:18 +08:00
|
|
|
shell: ceph-disk list | grep osd.{{ item.0 }}, | grep -Eo '/dev/([hsv]d[a-z]{1,2})[0-9]{1,2}|/dev/nvme[0-9]n[0-9]p[0-9]'
|
2018-07-19 21:45:55 +08:00
|
|
|
with_together:
|
|
|
|
- "{{ osd_to_kill.split(',') }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
register: osd_to_kill_disks_dedicated_non_container
|
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
when:
|
|
|
|
- not containerized_deployment
|
|
|
|
|
2018-04-20 17:13:51 +08:00
|
|
|
# if nvme then osd_to_kill_disks is nvme0n1, we need nvme0
|
|
|
|
# if ssd or hdd then osd_to_kill_disks is sda1, we need sda
|
2019-08-06 02:32:18 +08:00
|
|
|
- name: stop osd services with device (container)
|
2017-09-18 23:45:08 +08:00
|
|
|
service:
|
2018-04-20 17:13:51 +08:00
|
|
|
name: "ceph-osd@{{ item.0.stdout[:-2] | regex_replace('/dev/', '') if 'nvme' in item.0.stdout else item.0.stdout[:-1] | regex_replace('/dev/', '') }}"
|
2017-09-18 23:45:08 +08:00
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
with_together:
|
|
|
|
- "{{ osd_to_kill_disks.results }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
when:
|
|
|
|
- containerized_deployment
|
|
|
|
|
2019-08-06 02:32:18 +08:00
|
|
|
- name: stop osd services with ID (container)
|
|
|
|
service:
|
|
|
|
name: "ceph-osd@{{ item.0 }}"
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
with_together:
|
|
|
|
- "{{ osd_to_kill.split(',') }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
when: containerized_deployment | bool
|
|
|
|
|
2018-07-18 22:20:47 +08:00
|
|
|
- name: resolve parent device
|
2018-09-13 17:18:56 +08:00
|
|
|
command: lsblk --nodeps -no pkname "{{ item.0.stdout }}"
|
2018-07-18 22:20:47 +08:00
|
|
|
register: resolved_parent_device
|
2018-09-13 17:18:56 +08:00
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
with_together:
|
2018-07-18 22:20:47 +08:00
|
|
|
- "{{ osd_to_kill_disks.results }}"
|
2018-09-13 17:18:56 +08:00
|
|
|
- "{{ osd_hosts }}"
|
2018-07-18 22:20:47 +08:00
|
|
|
|
|
|
|
- name: zap ceph osd disks
|
|
|
|
shell: |
|
|
|
|
docker run --rm \
|
|
|
|
--privileged=true \
|
2018-09-14 19:45:48 +08:00
|
|
|
--name ceph-osd-zap-{{ hostvars[item.1]['ansible_hostname'] }}-{{ item.0.stdout }} \
|
2018-07-18 22:20:47 +08:00
|
|
|
-v /dev/:/dev/ \
|
2018-09-13 17:18:56 +08:00
|
|
|
-e OSD_DEVICE=/dev/{{ item.0.stdout }} \
|
2018-07-18 22:20:47 +08:00
|
|
|
{{ ceph_docker_registry }}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} \
|
2019-07-09 15:48:08 +08:00
|
|
|
zap_device;
|
|
|
|
parted -s /dev/{{ item.0.stdout }} mklabel msdos
|
2018-09-13 17:18:56 +08:00
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
with_together:
|
2018-07-18 22:20:47 +08:00
|
|
|
- "{{ resolved_parent_device.results }}"
|
2018-09-13 17:18:56 +08:00
|
|
|
- "{{ osd_hosts }}"
|
2018-07-18 22:20:47 +08:00
|
|
|
when:
|
|
|
|
- containerized_deployment
|
|
|
|
|
2019-07-09 19:12:54 +08:00
|
|
|
- name: remove prepare container
|
|
|
|
command: docker rm ceph-osd-prepare-"{{ hostvars[item.1]['ansible_hostname'] }}"-"{{ item.0.stdout }}"
|
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
with_together:
|
|
|
|
- "{{ resolved_parent_device.results }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
when:
|
|
|
|
- containerized_deployment
|
|
|
|
|
2018-07-19 21:45:55 +08:00
|
|
|
- name: zap ceph osd partitions from dedicated devices
|
|
|
|
shell: |
|
2018-09-14 19:45:48 +08:00
|
|
|
for osd in {{ ' '.join(item.1.stdout_lines) }}
|
|
|
|
do
|
|
|
|
if [ -b "${osd}" ];
|
|
|
|
pkname=$(lsblk --nodeps -no PKNAME "${osd}");
|
|
|
|
then
|
|
|
|
echo zapping ceph osd partitions "${osd}";
|
|
|
|
docker run --rm \
|
|
|
|
--privileged=true \
|
|
|
|
--name ceph-osd-zap-{{ hostvars[item.0]['ansible_hostname'] }}-$(basename "${osd}") \
|
|
|
|
-v /dev/:/dev/ \
|
|
|
|
-e OSD_DEVICE="${osd}" \
|
|
|
|
{{ ceph_docker_registry }}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} \
|
|
|
|
zap_device;
|
|
|
|
partprobe /dev/"${pkname}";
|
|
|
|
fi
|
|
|
|
done
|
2018-07-19 21:45:55 +08:00
|
|
|
with_together:
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
- "{{ osd_to_kill_disks_dedicated.results }}"
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
when:
|
|
|
|
- containerized_deployment
|
|
|
|
- item.1 | length > 0
|
|
|
|
|
2017-08-31 06:07:28 +08:00
|
|
|
- name: deactivating osd(s)
|
|
|
|
command: ceph-disk deactivate --cluster {{ cluster }} --deactivate-by-id {{ item.0 }} --mark-out
|
2017-09-13 07:05:34 +08:00
|
|
|
run_once: true
|
2017-08-31 06:07:28 +08:00
|
|
|
with_together:
|
|
|
|
- "{{ osd_to_kill.split(',') }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.1 }}"
|
2017-09-18 23:45:08 +08:00
|
|
|
when:
|
|
|
|
- not containerized_deployment
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: destroying osd(s)
|
|
|
|
command: ceph-disk destroy --cluster {{ cluster }} --destroy-by-id {{ item.0 }} --zap
|
2017-09-13 07:05:34 +08:00
|
|
|
run_once: true
|
2017-08-31 06:07:28 +08:00
|
|
|
with_together:
|
|
|
|
- "{{ osd_to_kill.split(',') }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.1 }}"
|
2017-09-18 23:45:08 +08:00
|
|
|
when:
|
|
|
|
- not containerized_deployment
|
2017-08-31 06:07:28 +08:00
|
|
|
|
2019-07-09 15:48:08 +08:00
|
|
|
- name: remove gpt header on device
|
|
|
|
command: parted -s /dev/"{{ item.0.stdout }}" mklabel msdos
|
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
with_together:
|
|
|
|
- "{{ resolved_parent_device.results }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
|
2017-08-31 06:07:28 +08:00
|
|
|
- name: remove osd(s) from crush_map when ceph-disk destroy fail
|
2017-10-07 01:15:26 +08:00
|
|
|
command: "{{ docker_exec_cmd }} ceph --cluster {{ cluster }} osd crush remove osd.{{ item }}"
|
2017-09-13 07:05:34 +08:00
|
|
|
run_once: true
|
2017-08-31 06:07:28 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
2017-10-07 01:15:26 +08:00
|
|
|
with_items: "{{ osd_to_kill.split(',') }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: delete osd(s) auth key when ceph-disk destroy fail
|
2017-10-07 01:15:26 +08:00
|
|
|
command: "{{ docker_exec_cmd }} ceph --cluster {{ cluster }} auth del osd.{{ item }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
2017-10-07 01:15:26 +08:00
|
|
|
with_items: "{{ osd_to_kill.split(',') }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
|
|
|
|
- name: deallocate osd(s) id when ceph-disk destroy fail
|
2017-10-07 01:15:26 +08:00
|
|
|
command: "{{ docker_exec_cmd }} ceph --cluster {{ cluster }} osd rm {{ item }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
2017-10-07 01:15:26 +08:00
|
|
|
with_items: "{{ osd_to_kill.split(',') }}"
|
2017-08-31 06:07:28 +08:00
|
|
|
|
2018-07-19 21:45:55 +08:00
|
|
|
- name: zap dedicated partitions
|
|
|
|
shell: |
|
2018-09-14 19:45:48 +08:00
|
|
|
for osd in {{ ' '.join(item.1.stdout_lines) }}
|
|
|
|
do
|
|
|
|
if [ -b "${osd}" ];
|
|
|
|
then
|
|
|
|
echo zapping dedicated partition "${osd}"
|
|
|
|
pkname=$(lsblk --nodeps -no PKNAME "${osd}")
|
|
|
|
wipefs --all "${osd}"
|
|
|
|
dd if=/dev/zero of="${osd}" bs=1M count=10
|
|
|
|
partition_nb=$(echo "${osd}" | grep -oE '[0-9]{1,2}$')
|
|
|
|
sgdisk --delete $partition_nb /dev/"${pkname}"
|
|
|
|
partprobe /dev/"${pkname}"
|
|
|
|
fi
|
|
|
|
done
|
2018-07-19 21:45:55 +08:00
|
|
|
with_together:
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
- "{{ osd_to_kill_disks_dedicated_non_container.results }}"
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
when:
|
|
|
|
- not containerized_deployment
|
|
|
|
- item.1 | length > 0
|
|
|
|
|
2019-08-06 02:32:18 +08:00
|
|
|
- name: remove ceph osd directory
|
|
|
|
file:
|
|
|
|
name: '/var/lib/ceph/osd/{{ cluster }}-{{ item.0 }}'
|
|
|
|
state: absent
|
|
|
|
with_together:
|
|
|
|
- "{{ osd_to_kill.split(',') }}"
|
|
|
|
- "{{ osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.1 }}"
|
|
|
|
|
2017-08-31 06:07:28 +08:00
|
|
|
- name: show ceph health
|
2017-09-18 23:45:08 +08:00
|
|
|
command: "{{ docker_exec_cmd }} ceph --cluster {{ cluster }} -s"
|
2017-08-31 06:07:28 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
|
|
|
|
|
|
|
- name: show ceph osd tree
|
2017-09-18 23:45:08 +08:00
|
|
|
command: "{{ docker_exec_cmd }} ceph --cluster {{ cluster }} osd tree"
|
2017-08-31 06:07:28 +08:00
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|