2018-11-01 02:17:16 +08:00
|
|
|
---
|
|
|
|
# This playbook shrinks Ceph OSDs that have been created with ceph-volume.
|
|
|
|
# It can remove any number of OSD(s) from the cluster and ALL THEIR DATA
|
|
|
|
#
|
|
|
|
# Use it like this:
|
2019-04-28 17:56:29 +08:00
|
|
|
# ansible-playbook shrink-osd.yml -e osd_to_kill=0,2,6
|
2018-11-01 02:17:16 +08:00
|
|
|
# Prompts for confirmation to shrink, defaults to no and
|
|
|
|
# doesn't shrink the cluster. yes shrinks the cluster.
|
|
|
|
#
|
2019-04-28 17:56:29 +08:00
|
|
|
# ansible-playbook -e ireallymeanit=yes|no shrink-osd.yml
|
2018-11-01 02:17:16 +08:00
|
|
|
# Overrides the prompt using -e option. Can be used in
|
|
|
|
# automation scripts to avoid interactive prompt.
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Gather facts and check the init system
|
2018-11-01 02:17:16 +08:00
|
|
|
hosts:
|
2024-02-13 07:48:13 +08:00
|
|
|
- mons
|
|
|
|
- osds
|
2018-11-01 02:17:16 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
become: true
|
2018-11-01 02:17:16 +08:00
|
|
|
tasks:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Gather facts on all Ceph hosts for following reference
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "gather facts on all Ceph hosts for following reference"
|
2018-11-01 02:17:16 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Confirm whether user really meant to remove osd(s) from the cluster
|
2024-02-13 07:48:13 +08:00
|
|
|
hosts: mons[0]
|
2018-11-01 02:17:16 +08:00
|
|
|
become: true
|
|
|
|
vars_prompt:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: ireallymeanit # noqa: name[casing]
|
2018-11-01 02:17:16 +08:00
|
|
|
prompt: Are you sure you want to shrink the cluster?
|
|
|
|
default: 'no'
|
2024-02-14 18:14:02 +08:00
|
|
|
private: false
|
2018-11-01 02:17:16 +08:00
|
|
|
vars:
|
|
|
|
mon_group_name: mons
|
|
|
|
osd_group_name: osds
|
|
|
|
|
2018-11-12 20:21:26 +08:00
|
|
|
pre_tasks:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Exit playbook, if user did not mean to shrink cluster
|
|
|
|
ansible.builtin.fail:
|
2018-11-01 02:17:16 +08:00
|
|
|
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'
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Exit playbook, if no osd(s) was/were given
|
|
|
|
ansible.builtin.fail:
|
2018-11-01 02:17:16 +08:00
|
|
|
msg: "osd_to_kill must be declared
|
|
|
|
Exiting shrink-osd playbook, no OSD(s) was/were removed.
|
|
|
|
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
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Check the osd ids passed have the correct format
|
|
|
|
ansible.builtin.fail:
|
2021-10-12 23:55:40 +08:00
|
|
|
msg: "The id {{ item }} has wrong format, please pass the number only"
|
|
|
|
with_items: "{{ osd_to_kill.split(',') }}"
|
2021-10-20 15:45:16 +08:00
|
|
|
when: not item is regex("^\d+$")
|
2021-10-12 23:55:40 +08:00
|
|
|
|
2018-11-12 20:21:26 +08:00
|
|
|
tasks:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Import ceph-defaults role
|
|
|
|
ansible.builtin.import_role:
|
2018-11-08 04:54:45 +08:00
|
|
|
name: ceph-defaults
|
2018-11-01 02:17:16 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Import ceph-facts role
|
|
|
|
ansible.builtin.import_role:
|
2018-12-10 22:46:32 +08:00
|
|
|
name: ceph-facts
|
2020-02-26 23:20:05 +08:00
|
|
|
tasks_from: container_binary
|
2018-12-10 22:46:32 +08:00
|
|
|
|
2018-11-12 20:21:26 +08:00
|
|
|
post_tasks:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact container_exec_cmd build docker exec command (containerized)
|
|
|
|
ansible.builtin.set_fact:
|
2021-03-03 22:43:50 +08:00
|
|
|
container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ ansible_facts['hostname'] }}"
|
2019-05-22 16:02:42 +08:00
|
|
|
when: containerized_deployment | bool
|
2018-11-01 02:17:16 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Exit playbook, if can not connect to the cluster
|
|
|
|
ansible.builtin.command: "{{ container_exec_cmd }} timeout 5 ceph --cluster {{ cluster }} health"
|
2018-11-01 02:17:16 +08:00
|
|
|
register: ceph_health
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|
2018-11-01 02:17:16 +08:00
|
|
|
until: ceph_health.stdout.find("HEALTH") > -1
|
|
|
|
retries: 5
|
|
|
|
delay: 2
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Find the host(s) where the osd(s) is/are running on
|
|
|
|
ansible.builtin.command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} osd find {{ item }}"
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|
2018-11-01 02:17:16 +08:00
|
|
|
with_items: "{{ osd_to_kill.split(',') }}"
|
|
|
|
register: find_osd_hosts
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact osd_hosts
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
osd_hosts: "{{ osd_hosts | default([]) + [[(item.stdout | from_json).crush_location.host, (item.stdout | from_json).osd_fsid, item.item]] }}"
|
2018-11-01 02:17:16 +08:00
|
|
|
with_items: "{{ find_osd_hosts.results }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact _osd_hosts
|
|
|
|
ansible.builtin.set_fact:
|
2020-02-20 01:30:14 +08:00
|
|
|
_osd_hosts: "{{ _osd_hosts | default([]) + [ [ item.0, item.2, item.3 ] ] }}"
|
2019-12-09 22:52:26 +08:00
|
|
|
with_nested:
|
|
|
|
- "{{ groups.get(osd_group_name) }}"
|
|
|
|
- "{{ osd_hosts }}"
|
2021-03-03 22:43:50 +08:00
|
|
|
when: hostvars[item.0]['ansible_facts']['hostname'] == item.1
|
2019-12-09 22:52:26 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact host_list
|
|
|
|
ansible.builtin.set_fact:
|
2022-07-04 17:54:41 +08:00
|
|
|
host_list: "{{ host_list | default([]) | union([item.0]) }}"
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Get ceph-volume lvm list data
|
2020-11-19 06:20:45 +08:00
|
|
|
ceph_volume:
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
action: list
|
|
|
|
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 }}"
|
2020-02-20 01:30:14 +08:00
|
|
|
register: _lvm_list_data
|
2022-07-04 17:54:41 +08:00
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
loop: "{{ host_list }}"
|
2020-02-20 01:30:14 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact _lvm_list
|
|
|
|
ansible.builtin.set_fact:
|
2020-02-20 01:30:14 +08:00
|
|
|
_lvm_list: "{{ _lvm_list | default({}) | combine(item.stdout | from_json) }}"
|
|
|
|
with_items: "{{ _lvm_list_data.results }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Refresh /etc/ceph/osd files non containerized_deployment
|
2022-07-04 17:54:41 +08:00
|
|
|
ceph_volume_simple_scan:
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
force: true
|
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
loop: "{{ host_list }}"
|
|
|
|
when: not containerized_deployment | bool
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Get osd unit status
|
|
|
|
ansible.builtin.systemd:
|
2023-03-02 04:26:54 +08:00
|
|
|
name: ceph-osd@{{ item.2 }}
|
|
|
|
register: osd_status
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
when:
|
|
|
|
- containerized_deployment | bool
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Refresh /etc/ceph/osd files containerized_deployment
|
|
|
|
ansible.builtin.command: "{{ container_binary }} exec ceph-osd-{{ item.2 }} ceph-volume simple scan --force /var/lib/ceph/osd/{{ cluster }}-{{ item.2 }}"
|
2022-07-04 17:54:41 +08:00
|
|
|
changed_when: false
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
loop: "{{ _osd_hosts }}"
|
2023-03-02 04:26:54 +08:00
|
|
|
when:
|
|
|
|
- containerized_deployment | bool
|
|
|
|
- item.2 not in _lvm_list.keys()
|
|
|
|
- osd_status.results[0].status.ActiveState == 'active'
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Refresh /etc/ceph/osd files containerized_deployment when OSD container is down
|
|
|
|
when:
|
|
|
|
- containerized_deployment | bool
|
|
|
|
- osd_status.results[0].status.ActiveState != 'active'
|
2023-03-02 04:26:54 +08:00
|
|
|
block:
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Create tmp osd folder
|
|
|
|
ansible.builtin.file:
|
2023-03-02 04:26:54 +08:00
|
|
|
path: /var/lib/ceph/tmp/{{ cluster }}-{{ item.2 }}
|
|
|
|
state: directory
|
|
|
|
mode: '0755'
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
when: item.2 not in _lvm_list.keys()
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Activate OSD
|
|
|
|
ansible.builtin.command: |
|
2023-03-02 04:26:54 +08:00
|
|
|
{{ container_binary }} run -ti --pids-limit=-1 --rm --net=host --privileged=true --pid=host --ipc=host --cpus=1
|
|
|
|
-v /dev:/dev -v /etc/localtime:/etc/localtime:ro
|
|
|
|
-v /var/lib/ceph/tmp/:/var/lib/ceph/osd:z,rshared
|
|
|
|
-v /etc/ceph:/etc/ceph:z -v /var/run/ceph:/var/run/ceph:z
|
|
|
|
-v /var/run/udev/:/var/run/udev/ -v /var/log/ceph:/var/log/ceph:z
|
|
|
|
-e OSD_BLUESTORE=1 -e OSD_FILESTORE=0 -e OSD_DMCRYPT=0 -e CLUSTER=ceph -e DEBUG=verbose
|
|
|
|
-e TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=134217728 -v /run/lvm/:/run/lvm/
|
|
|
|
-e CEPH_DAEMON=OSD_CEPH_VOLUME_ACTIVATE -e CONTAINER_IMAGE={{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag }}
|
|
|
|
-e OSD_ID={{ item.2 }}
|
|
|
|
--entrypoint=ceph-volume
|
|
|
|
{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag }}
|
|
|
|
simple activate {{ item.2 }} {{ item.1 }} --no-systemd
|
|
|
|
changed_when: false
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
when: item.2 not in _lvm_list.keys()
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Simple scan
|
|
|
|
ansible.builtin.command: |
|
2023-03-02 04:26:54 +08:00
|
|
|
{{ container_binary }} run -ti --pids-limit=-1 --rm --net=host --privileged=true --pid=host --ipc=host --cpus=1
|
|
|
|
-v /dev:/dev -v /etc/localtime:/etc/localtime:ro
|
|
|
|
-v /var/lib/ceph/tmp/:/var/lib/ceph/osd:z,rshared
|
|
|
|
-v /etc/ceph:/etc/ceph:z -v /var/run/ceph:/var/run/ceph:z
|
|
|
|
-v /var/run/udev/:/var/run/udev/ -v /var/log/ceph:/var/log/ceph:z
|
|
|
|
-e OSD_BLUESTORE=1 -e OSD_FILESTORE=0 -e OSD_DMCRYPT=0 -e CLUSTER=ceph -e DEBUG=verbose
|
|
|
|
-e TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=134217728 -v /run/lvm/:/run/lvm/
|
|
|
|
-e CEPH_DAEMON=OSD_CEPH_VOLUME_ACTIVATE -e CONTAINER_IMAGE={{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag }}
|
|
|
|
-e OSD_ID={{ item.2 }}
|
|
|
|
--entrypoint=ceph-volume
|
|
|
|
{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag }}
|
|
|
|
simple scan --force /var/lib/ceph/osd/{{ cluster }}-{{ item.2 }}
|
|
|
|
changed_when: false
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
when: item.2 not in _lvm_list.keys()
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Umount OSD temp folder
|
|
|
|
ansible.posix.mount:
|
2023-03-02 04:26:54 +08:00
|
|
|
path: /var/lib/ceph/tmp/{{ cluster }}-{{ item.2 }}
|
|
|
|
state: unmounted
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
when: item.2 not in _lvm_list.keys()
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Remove OSD temp folder
|
|
|
|
ansible.builtin.file:
|
2023-03-02 04:26:54 +08:00
|
|
|
path: /var/lib/ceph/tmp/{{ cluster }}-{{ item.2 }}
|
|
|
|
state: absent
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
when: item.2 not in _lvm_list.keys()
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Find /etc/ceph/osd files
|
|
|
|
ansible.builtin.find:
|
2020-02-20 01:30:14 +08:00
|
|
|
paths: /etc/ceph/osd
|
|
|
|
pattern: "{{ item.2 }}-*"
|
|
|
|
register: ceph_osd_data
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
when: item.2 not in _lvm_list.keys()
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Slurp ceph osd files content
|
|
|
|
ansible.builtin.slurp:
|
2020-02-20 01:30:14 +08:00
|
|
|
src: "{{ item['files'][0]['path'] }}"
|
|
|
|
delegate_to: "{{ item.item.0 }}"
|
|
|
|
register: ceph_osd_files_content
|
|
|
|
loop: "{{ ceph_osd_data.results }}"
|
2020-07-28 19:47:26 +08:00
|
|
|
when:
|
|
|
|
- item.skipped is undefined
|
|
|
|
- item.matched > 0
|
2020-02-20 01:30:14 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Set_fact ceph_osd_files_json
|
|
|
|
ansible.builtin.set_fact:
|
2020-02-20 01:30:14 +08:00
|
|
|
ceph_osd_data_json: "{{ ceph_osd_data_json | default({}) | combine({ item.item.item.2: item.content | b64decode | from_json}) }}"
|
|
|
|
with_items: "{{ ceph_osd_files_content.results }}"
|
|
|
|
when: item.skipped is undefined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Mark osd(s) out of the cluster
|
2020-11-21 06:50:59 +08:00
|
|
|
ceph_osd:
|
|
|
|
ids: "{{ osd_to_kill.split(',') }}"
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
state: out
|
|
|
|
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 }}"
|
2018-11-01 02:17:16 +08:00
|
|
|
run_once: true
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Stop osd(s) service
|
|
|
|
ansible.builtin.service:
|
2020-02-20 01:30:14 +08:00
|
|
|
name: ceph-osd@{{ item.2 }}
|
2018-11-01 02:17:16 +08:00
|
|
|
state: stopped
|
2024-02-14 18:14:02 +08:00
|
|
|
enabled: false
|
2020-02-20 01:30:14 +08:00
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Umount osd lockbox
|
2022-06-15 00:18:36 +08:00
|
|
|
ansible.posix.mount:
|
2020-02-20 01:30:14 +08:00
|
|
|
path: "/var/lib/ceph/osd-lockbox/{{ ceph_osd_data_json[item.2]['data']['uuid'] }}"
|
2020-07-22 22:08:15 +08:00
|
|
|
state: absent
|
2020-02-20 01:30:14 +08:00
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
when:
|
|
|
|
- not containerized_deployment | bool
|
|
|
|
- item.2 not in _lvm_list.keys()
|
|
|
|
- ceph_osd_data_json[item.2]['encrypted'] | default(False) | bool
|
|
|
|
- ceph_osd_data_json[item.2]['data']['uuid'] is defined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Umount osd data
|
2022-06-15 00:18:36 +08:00
|
|
|
ansible.posix.mount:
|
2020-02-20 01:30:14 +08:00
|
|
|
path: "/var/lib/ceph/osd/{{ cluster }}-{{ item.2 }}"
|
2020-07-22 22:08:15 +08:00
|
|
|
state: absent
|
2020-02-20 01:30:14 +08:00
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.0 }}"
|
2020-07-22 22:08:15 +08:00
|
|
|
when: not containerized_deployment | bool
|
2020-02-20 01:30:14 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Get parent device for data partition
|
|
|
|
ansible.builtin.command: lsblk --noheadings --output PKNAME --nodeps "{{ ceph_osd_data_json[item.2]['data']['path'] }}"
|
2020-02-20 01:30:14 +08:00
|
|
|
register: parent_device_data_part
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.0 }}"
|
2024-02-14 18:14:02 +08:00
|
|
|
changed_when: false
|
2020-02-20 01:30:14 +08:00
|
|
|
when:
|
|
|
|
- item.2 not in _lvm_list.keys()
|
|
|
|
- ceph_osd_data_json[item.2]['data']['path'] is defined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Add pkname information in ceph_osd_data_json
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
ceph_osd_data_json: "{{ ceph_osd_data_json | default({}) | combine({item.item[2]: {'pkname_data': '/dev/' + item.stdout}}, recursive=True) }}"
|
2020-02-20 01:30:14 +08:00
|
|
|
loop: "{{ parent_device_data_part.results }}"
|
|
|
|
when: item.skipped is undefined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Close dmcrypt close on devices if needed
|
|
|
|
ansible.builtin.command: "cryptsetup close {{ ceph_osd_data_json[item.2][item.3]['uuid'] }}"
|
2020-02-20 01:30:14 +08:00
|
|
|
with_nested:
|
|
|
|
- "{{ _osd_hosts }}"
|
2024-02-14 18:14:02 +08:00
|
|
|
- ['block_dmcrypt', 'block.db_dmcrypt', 'block.wal_dmcrypt', 'data', 'journal_dmcrypt']
|
2020-02-20 01:30:14 +08:00
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
failed_when: false
|
|
|
|
register: result
|
|
|
|
until: result is succeeded
|
2024-02-14 18:14:02 +08:00
|
|
|
changed_when: false
|
2020-02-20 01:30:14 +08:00
|
|
|
when:
|
|
|
|
- item.2 not in _lvm_list.keys()
|
2020-07-28 19:47:26 +08:00
|
|
|
- ceph_osd_data_json[item.2]['encrypted'] | default(False) | bool
|
2020-02-20 01:30:14 +08:00
|
|
|
- ceph_osd_data_json[item.2][item.3] is defined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Use ceph-volume lvm zap to destroy all partitions
|
2020-11-19 06:20:45 +08:00
|
|
|
ceph_volume:
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
action: zap
|
|
|
|
destroy: true
|
|
|
|
data: "{{ ceph_osd_data_json[item.2]['pkname_data'] if item.3 == 'data' else ceph_osd_data_json[item.2][item.3]['path'] }}"
|
|
|
|
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 }}"
|
2020-02-20 01:30:14 +08:00
|
|
|
with_nested:
|
|
|
|
- "{{ _osd_hosts }}"
|
2024-02-14 18:14:02 +08:00
|
|
|
- ['block', 'block.db', 'block.wal', 'journal', 'data']
|
2020-02-20 01:30:14 +08:00
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
failed_when: false
|
|
|
|
register: result
|
|
|
|
when:
|
|
|
|
- item.2 not in _lvm_list.keys()
|
|
|
|
- ceph_osd_data_json[item.2][item.3] is defined
|
2018-11-01 02:17:16 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Zap osd devices
|
2018-11-01 02:17:16 +08:00
|
|
|
ceph_volume:
|
|
|
|
action: "zap"
|
2019-01-18 07:08:19 +08:00
|
|
|
osd_fsid: "{{ item.1 }}"
|
2018-11-01 02:17:16 +08:00
|
|
|
environment:
|
2020-08-06 00:02:48 +08:00
|
|
|
CEPH_VOLUME_DEBUG: "{{ ceph_volume_debug }}"
|
2020-09-26 00:15:02 +08:00
|
|
|
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
|
2018-11-23 00:32:25 +08:00
|
|
|
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
|
2019-01-18 07:08:19 +08:00
|
|
|
delegate_to: "{{ item.0 }}"
|
2019-12-09 22:52:26 +08:00
|
|
|
loop: "{{ _osd_hosts }}"
|
2020-02-20 01:30:14 +08:00
|
|
|
when: item.2 in _lvm_list.keys()
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Ensure osds are marked down
|
2020-11-21 06:50:59 +08:00
|
|
|
ceph_osd:
|
|
|
|
ids: "{{ osd_to_kill.split(',') }}"
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
state: down
|
|
|
|
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 }}"
|
2020-02-20 01:30:14 +08:00
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ groups[mon_group_name][0] }}"
|
2018-11-01 02:17:16 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Purge osd(s) from the cluster
|
2020-11-21 06:50:59 +08:00
|
|
|
ceph_osd:
|
|
|
|
ids: "{{ item }}"
|
|
|
|
cluster: "{{ cluster }}"
|
|
|
|
state: purge
|
|
|
|
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 }}"
|
2018-11-01 02:17:16 +08:00
|
|
|
run_once: true
|
|
|
|
with_items: "{{ osd_to_kill.split(',') }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Remove osd data dir
|
|
|
|
ansible.builtin.file:
|
2020-07-22 22:08:15 +08:00
|
|
|
path: "/var/lib/ceph/osd/{{ cluster }}-{{ item.2 }}"
|
|
|
|
state: absent
|
|
|
|
loop: "{{ _osd_hosts }}"
|
|
|
|
delegate_to: "{{ item.0 }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Show ceph health
|
|
|
|
ansible.builtin.command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} -s"
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|
2018-11-01 02:17:16 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Show ceph osd tree
|
|
|
|
ansible.builtin.command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} osd tree"
|
2020-10-02 18:55:53 +08:00
|
|
|
changed_when: false
|