ceph-ansible/roles/ceph-osd/tasks/check_devices_auto.yml

70 lines
2.3 KiB
YAML
Raw Normal View History

---
- name: check if the device is a partition (autodiscover disks)
shell: "readlink -f /dev/{{ item.key }} | egrep '/dev/([hsv]d[a-z]{1,2}|cciss/c[0-9]d[0-9]p|nvme[0-9]n[0-9]p)[0-9]{1,2}|fio[a-z]{1,2}[0-9]{1,2}$'"
with_dict: "{{ ansible_devices }}"
changed_when: false
failed_when: false
always_run: true
register: ispartition_results
when:
- ansible_devices is defined
- item.value.removable == "0"
- name: check if any of the raw partitions are mounted
shell: "mount |grep -sq '^/dev/{{ item.key }} '"
args:
warn: false
ignore_errors: yes
with_dict: "{{ ansible_devices }}"
register: mount_cmd
changed_when: false
always_run: true
when:
- ansible_devices is defined
- item.value.removable == "0"
- item.value.partitions|count == 0
- item.value.holders|count == 0
- name: fail if any of the raw partitions are mounted
fail:
msg: "OSD device autodetection failed because one or more raw partitions is mounted on the host."
when: item.rc == 0
with_items: "{{ mount_cmd.results }}"
- name: check the partition status of the osd disks (autodiscover disks)
shell: "parted --script /dev/{{ item.key }} print > /dev/null 2>&1"
with_dict: "{{ ansible_devices }}"
changed_when: false
failed_when: false
always_run: true
register: osd_partition_status_results
when:
- ansible_devices is defined
- item.value.removable == "0"
- item.value.partitions|count == 0
- item.value.holders|count == 0
- name: fix partitions gpt header or labels of the osd disks (autodiscover disks)
shell: "sgdisk --zap-all --clear --mbrtogpt -- '/dev/{{ item.0.item.key }}' || sgdisk --zap-all --clear --mbrtogpt -- '/dev/{{ item.0.item.key }}'"
with_together:
- "{{ osd_partition_status_results.results }}"
- "{{ ansible_devices }}"
changed_when: false
when:
- ansible_devices is defined
- item.0.item.value.removable == "0"
- item.0.item.value.partitions|count == 0
- item.0.item.value.holders|count == 0
- item.0.rc != 0
- name: check if a partition named 'ceph' exists (autodiscover disks)
shell: "parted --script /dev/{{ item.key }} print | egrep -sq '^ 1.*ceph'"
with_dict: "{{ ansible_devices }}"
changed_when: false
failed_when: false
always_run: true
register: parted_results
when:
- ansible_devices is defined
- item.value.removable == "0"