2017-04-13 10:56:38 +08:00
|
|
|
---
|
|
|
|
# This playbook use to migrate activity osd(s) journal to SSD.
|
|
|
|
#
|
|
|
|
# You should define `osds_journal_devices` variable for host which osd(s) journal migrate to.
|
|
|
|
#
|
|
|
|
# For example in host_vars/hostname1.yml
|
|
|
|
#
|
|
|
|
# osds_journal_devices:
|
|
|
|
# - device_name: /dev/sdd
|
|
|
|
# partitions:
|
|
|
|
# - index: 1
|
|
|
|
# size: 10G
|
|
|
|
# osd_id: 0
|
|
|
|
# - index: 2
|
|
|
|
# size: 10G
|
|
|
|
# osd_id: 1
|
|
|
|
# - device_name: /dev/sdf
|
|
|
|
# partitions:
|
|
|
|
# - index: 1
|
|
|
|
# size: 10G
|
|
|
|
# osd_id: 2
|
|
|
|
#
|
|
|
|
# @param device_name: The full device path of new ssd.
|
|
|
|
# @param partitions: The custom partition layout of ssd.
|
|
|
|
# @param index: The index of this partition.
|
|
|
|
# @param size: The size of this partition.
|
|
|
|
# @param osd_id: Which osds's journal this partition for.
|
|
|
|
#
|
|
|
|
# ansible-playbook migrate-journal-to-ssd.yml
|
|
|
|
# The playbook will migrate osd(s) journal to ssd device which you define in host_vars.
|
|
|
|
|
|
|
|
- vars:
|
|
|
|
osd_group_name: osds
|
|
|
|
journal_typecode: 45b0969e-9b03-4f30-b4c6-b4b80ceff106
|
|
|
|
osds_journal_devices: []
|
2019-04-01 23:46:15 +08:00
|
|
|
hosts: "{{ osd_group_name }}"
|
2017-04-13 10:56:38 +08:00
|
|
|
serial: 1
|
|
|
|
tasks:
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Get osd(s) if directory stat
|
|
|
|
ansible.builtin.stat:
|
2017-04-13 10:56:38 +08:00
|
|
|
path: "/var/lib/ceph/osd/{{ cluster }}-{{ item.1.osd_id }}/journal_uuid"
|
|
|
|
register: osds_dir_stat
|
|
|
|
with_subelements:
|
|
|
|
- "{{ osds_journal_devices }}"
|
|
|
|
- partitions
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Exit playbook osd(s) is not on this host
|
|
|
|
ansible.builtin.fail:
|
2017-04-13 10:56:38 +08:00
|
|
|
msg: exit playbook osd(s) is not on this host
|
|
|
|
with_items:
|
|
|
|
osds_dir_stat.results
|
2019-04-01 23:46:15 +08:00
|
|
|
when: osds_dir_stat is defined and item.stat.exists == false
|
2017-04-13 10:56:38 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Install sgdisk(gdisk)
|
|
|
|
ansible.builtin.package:
|
2017-04-13 10:56:38 +08:00
|
|
|
name: gdisk
|
|
|
|
state: present
|
2018-12-19 21:55:01 +08:00
|
|
|
register: result
|
|
|
|
until: result is succeeded
|
2017-04-13 10:56:38 +08:00
|
|
|
when: osds_journal_devices is defined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Generate uuid for osds journal
|
|
|
|
ansible.builtin.command: uuidgen
|
2017-04-13 10:56:38 +08:00
|
|
|
register: osds
|
|
|
|
with_subelements:
|
|
|
|
- "{{ osds_journal_devices }}"
|
|
|
|
- partitions
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Make osd partitions on ssd
|
|
|
|
ansible.builtin.shell: >
|
2017-04-13 10:56:38 +08:00
|
|
|
sgdisk --new={{item.item[1].index}}:0:+{{item.item[1].size}} "--change-name={{ item.item[1].index }}:ceph journal"
|
|
|
|
--typecode={{ item.item[1].index }}:{{ journal_typecode }}
|
|
|
|
--partition-guid={{ item.item[1].index }}:{{ item.stdout }}
|
|
|
|
--mbrtogpt -- {{ item.item[0].device_name }}
|
2019-04-01 23:46:15 +08:00
|
|
|
with_items: "{{ osds.results }}"
|
2017-04-13 10:56:38 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Stop osd(s) service
|
|
|
|
ansible.builtin.service:
|
2017-04-13 10:56:38 +08:00
|
|
|
name: "ceph-osd@{{ item.item[1].osd_id }}"
|
|
|
|
state: stopped
|
2019-04-01 23:46:15 +08:00
|
|
|
with_items: "{{ osds.results }}"
|
2017-04-13 10:56:38 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Flush osd(s) journal
|
|
|
|
ansible.builtin.command: ceph-osd -i {{ item.item[1].osd_id }} --flush-journal --cluster {{ cluster }}
|
2019-04-01 23:46:15 +08:00
|
|
|
with_items: "{{ osds.results }}"
|
2017-04-13 10:56:38 +08:00
|
|
|
when: osds_journal_devices is defined
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Update osd(s) journal soft link
|
|
|
|
ansible.builtin.command: ln -sf /dev/disk/by-partuuid/{{ item.stdout }} /var/lib/ceph/osd/{{ cluster }}-{{ item.item[1].osd_id }}/journal
|
2019-04-01 23:46:15 +08:00
|
|
|
with_items: "{{ osds.results }}"
|
2017-04-13 10:56:38 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Update osd(s) journal uuid
|
|
|
|
ansible.builtin.command: echo {{ item.stdout }} > /var/lib/ceph/osd/{{ cluster }}-{{ item.item[1].osd_id }}/journal_uuid
|
2019-04-01 23:46:15 +08:00
|
|
|
with_items: "{{ osds.results }}"
|
2017-04-13 10:56:38 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Initialize osd(s) new journal
|
|
|
|
ansible.builtin.command: ceph-osd -i {{ item.item[1].osd_id }} --mkjournal --cluster {{ cluster }}
|
2019-04-01 23:46:15 +08:00
|
|
|
with_items: "{{ osds.results }}"
|
2017-04-13 10:56:38 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Start osd(s) service
|
|
|
|
ansible.builtin.service:
|
2017-04-13 10:56:38 +08:00
|
|
|
name: "ceph-osd@{{ item.item[1].osd_id }}"
|
|
|
|
state: started
|
2019-04-01 23:46:15 +08:00
|
|
|
with_items: "{{ osds.results }}"
|