2016-12-15 02:14:47 +08:00
|
|
|
---
|
2017-03-02 12:24:44 +08:00
|
|
|
# This playbook will make custom partition layout for your osd hosts.
|
2016-12-15 02:14:47 +08:00
|
|
|
# You should define `devices` variable for every host.
|
|
|
|
#
|
|
|
|
# For example, in host_vars/hostname1
|
|
|
|
#
|
|
|
|
# devices:
|
|
|
|
# - device_name: sdb
|
|
|
|
# partitions:
|
|
|
|
# - index: 1
|
|
|
|
# size: 10G
|
|
|
|
# type: data
|
|
|
|
# - index: 2
|
|
|
|
# size: 5G
|
|
|
|
# type: journal
|
|
|
|
# - device_name: sdc
|
|
|
|
# partitions:
|
|
|
|
# - index: 1
|
|
|
|
# size: 10G
|
|
|
|
# type: data
|
|
|
|
# - index: 2
|
|
|
|
# size: 5G
|
|
|
|
# type: journal
|
|
|
|
#
|
|
|
|
- vars:
|
|
|
|
osd_group_name: osds
|
|
|
|
journal_typecode: 45b0969e-9b03-4f30-b4c6-b4b80ceff106
|
|
|
|
data_typecode: 4fbd7e29-9d25-41b8-afd0-062c0ceff05d
|
2017-03-08 17:46:37 +08:00
|
|
|
devices: []
|
2019-04-01 23:46:15 +08:00
|
|
|
hosts: "{{ osd_group_name }}"
|
2016-12-15 02:14:47 +08:00
|
|
|
|
|
|
|
tasks:
|
2017-03-15 21:15:15 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Load a variable file for devices partition
|
2017-03-15 21:15:15 +08:00
|
|
|
include_vars: "{{ item }}"
|
|
|
|
with_first_found:
|
2017-03-06 10:33:22 +08:00
|
|
|
- files:
|
2021-03-03 22:43:50 +08:00
|
|
|
- "host_vars/{{ ansible_facts['hostname'] }}.yml"
|
2017-03-06 10:33:22 +08:00
|
|
|
- "host_vars/default.yml"
|
|
|
|
skip: true
|
2017-03-15 21:15:15 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Exit playbook, if devices not defined
|
|
|
|
ansible.builtin.fail:
|
2021-03-03 22:43:50 +08:00
|
|
|
msg: "devices must be define in host_vars/default.yml or host_vars/{{ ansible_facts['hostname'] }}.yml"
|
2017-03-06 10:33:22 +08:00
|
|
|
when: devices is not defined
|
2017-03-01 17:27:57 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Install sgdisk(gdisk)
|
|
|
|
ansible.builtin.package:
|
2016-12-15 02:14:47 +08:00
|
|
|
name: gdisk
|
|
|
|
state: present
|
2018-12-19 21:55:01 +08:00
|
|
|
register: result
|
|
|
|
until: result is succeeded
|
2016-12-15 02:14:47 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Erase all previous partitions(dangerous!!!)
|
|
|
|
ansible.builtin.shell: sgdisk --zap-all -- /dev/{{item.device_name}}
|
2016-12-15 02:14:47 +08:00
|
|
|
with_items: "{{ devices }}"
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Make osd partitions
|
|
|
|
ansible.builtin.shell: >
|
2016-12-15 02:14:47 +08:00
|
|
|
sgdisk --new={{item.1.index}}:0:+{{item.1.size}} "--change-name={{item.1.index}}:ceph {{item.1.type}}"
|
|
|
|
"--typecode={{item.1.index}}:{% if item.1.type=='data' %}{{data_typecode}}{% else %}{{journal_typecode}}{% endif %}"
|
|
|
|
--mbrtogpt -- /dev/{{item.0.device_name}}
|
|
|
|
with_subelements:
|
|
|
|
- "{{ devices }}"
|
|
|
|
- partitions
|
2017-07-27 11:55:30 +08:00
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
owner: 167
|
|
|
|
group: 167
|
2021-03-03 22:43:50 +08:00
|
|
|
when: ansible_facts['os_family'] == "RedHat"
|
2017-07-27 11:55:30 +08:00
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
owner: 64045
|
|
|
|
group: 64045
|
2021-03-03 22:43:50 +08:00
|
|
|
when: ansible_facts['os_family'] == "Debian"
|
2017-07-27 11:55:30 +08:00
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Change partitions ownership
|
|
|
|
ansible.builtin.file:
|
2017-07-27 11:55:30 +08:00
|
|
|
path: "/dev/{{item.0.device_name}}{{item.1.index}}"
|
|
|
|
owner: "{{ owner | default('root')}}"
|
|
|
|
group: "{{ group | default('disk')}}"
|
|
|
|
with_subelements:
|
|
|
|
- "{{ devices }}"
|
2017-08-02 11:01:26 +08:00
|
|
|
- partitions
|
|
|
|
when:
|
|
|
|
item.0.device_name | match('/dev/([hsv]d[a-z]{1,2}){1,2}$')
|
|
|
|
|
2024-02-14 18:14:02 +08:00
|
|
|
- name: Change partitions ownership
|
|
|
|
ansible.builtin.file:
|
2017-08-02 11:01:26 +08:00
|
|
|
path: "/dev/{{item.0.device_name}}p{{item.1.index}}"
|
|
|
|
owner: "{{ owner | default('root')}}"
|
|
|
|
group: "{{ group | default('disk')}}"
|
|
|
|
with_subelements:
|
|
|
|
- "{{ devices }}"
|
|
|
|
- partitions
|
2019-04-01 23:46:15 +08:00
|
|
|
when: item.0.device_name | match('/dev/(cciss/c[0-9]d[0-9]|nvme[0-9]n[0-9]){1,2}$')
|
|
|
|
...
|