- /usr/lib/udev/rules.d/95-ceph-osd.rules
- /usr/lib/udev/rules.d/60-ceph-by-parttypeuuid.rules
- - name: see if ceph-disk-created data partitions are present
- shell: |
- ls /dev/disk/by-partlabel | grep -q "ceph.*.data"
- failed_when: false
- register: ceph_data_partlabels
-
- - name: see if ceph-disk-created block partitions are present
- shell: |
- ls /dev/disk/by-partlabel | grep -q "ceph.*block$"
- failed_when: false
- register: ceph_block_partlabels
-
- - name: see if ceph-disk-created journal partitions are present
- shell: |
- ls /dev/disk/by-partlabel | grep -q "ceph.*.journal"
- failed_when: false
- register: ceph_journal_partlabels
-
- - name: see if ceph-disk-created block db partitions are present
- shell: |
- ls /dev/disk/by-partlabel | grep -q "ceph.*.block.db"
- failed_when: false
- register: ceph_db_partlabels
-
- - name: see if ceph-disk-created block wal partitions are present
- shell: |
- ls /dev/disk/by-partlabel | grep -q "ceph.*.block.wal"
- failed_when: false
- register: ceph_wal_partlabels
-
- - name: see if ceph-disk-created lockbox partitions are present
- shell: |
- ls /dev/disk/by-partlabel | grep -q "ceph.*.lockbox"
- failed_when: false
- register: ceph_lockbox_partlabels
-
-# Initial attempt, doing everything in Ansible...
-# - name: see if encrypted partitions are present
-# shell: blkid -t TYPE=crypto_LUKS -o value -s PARTUUID
-# register: encrypted_partuuid
-#
-# - name: find if these encrypted partitions are ceph data partitions
-# shell: blkid -t PARTLABEL="ceph data" -o value -s PARTUUID $(blkid -U {{ item }})
-# failed_when: false
-# with_items: "{{ encrypted_partuuid.stdout_lines }}"
-# when: "{{ encrypted_partuuid | length > 0 }}"
-# register: encrypted_partuuid_ceph_data
-#
-# - name: find if these encrypted partitions are ceph journal partitions
-# shell: blkid -t PARTLABEL="ceph journal" -o value -s PARTUUID $(blkid -U {{ item }})
-# failed_when: false
-# with_items: "{{ encrypted_partuuid.stdout_lines }}"
-# when: "{{ encrypted_partuuid | length > 0 }}"
-# register: encrypted_partuuid_ceph_journal
-#
-# - name: merge the list of ceph encrypted partitions
-# set_fact:
-# encrypted_partuuid_ceph: "{{ encrypted_partuuid_ceph_data + encrypted_partuuid_ceph_journal }}"
-
# NOTE(leseb): hope someone will find a more elegant way one day...
- name: see if encrypted partitions are present
shell: |
- name: get ceph data partitions
shell: |
blkid | awk -F: '/ceph data/ { print $1 }'
- when: ceph_data_partlabels.rc == 0
failed_when: false
register: ceph_data_partition_to_erase_path
- name: get ceph lockbox partitions
shell: |
blkid | awk '/ceph lockbox/ { sub (":", "", $1); print $1 }'
- when: ceph_lockbox_partlabels.rc == 0
failed_when: false
register: ceph_lockbox_partition_to_erase_path
- - name: zap osd disks
- shell: |
- if (echo "{{ item }}" | grep -Esq '[0-9]{1,2}$'); then
- raw_device=$(echo "{{ item }}" | grep -Eo '/dev/([hsv]d[a-z]{1,2}|cciss/c[0-9]d[0-9]|nvme[0-9]n[0-9]){1,2}')
- partition_nb=$(echo "{{ item }}" | grep -Eo '[0-9]{1,2}$')
- sgdisk --delete $partition_nb $raw_device
- udevadm settle --timeout=600
- else
- ceph-disk zap "{{ item }}"
- udevadm settle --timeout=600
- fi
- with_items:
- - "{{ ceph_data_partition_to_erase_path.stdout_lines | default([]) }}"
- - "{{ ceph_lockbox_partition_to_erase_path.stdout_lines | default([]) }}"
- when:
- - ceph_disk_present.rc == 0
- - (ceph_data_partlabels.rc == 0 or ceph_lockbox_partlabels.rc == 0)
-
# this should go away once 'ceph-volume lvm zap' is available
- name: remove osd logical volumes
command: "lvremove -f {{ item.data_vg }}/{{ item.data }}"
- name: get ceph block partitions
shell: |
blkid | awk '/ceph block"/ { sub (":", "", $1); print $1 }'
- when: ceph_block_partlabels.rc == 0
failed_when: false
register: ceph_block_partition_to_erase_path
- name: get ceph journal partitions
shell: |
blkid | awk '/ceph journal/ { sub (":", "", $1); print $1 }'
- when: ceph_journal_partlabels.rc == 0
failed_when: false
register: ceph_journal_partition_to_erase_path
- name: get ceph db partitions
shell: |
blkid | awk '/ceph block.db/ { sub (":", "", $1); print $1 }'
- when: ceph_db_partlabels.rc == 0
failed_when: false
register: ceph_db_partition_to_erase_path
- name: get ceph wal partitions
shell: |
blkid | awk '/ceph block.wal/ { sub (":", "", $1); print $1 }'
- when: ceph_wal_partlabels.rc == 0
failed_when: false
register: ceph_wal_partition_to_erase_path
+ - name: set_fact combined_devices_list
+ set_fact:
+ combined_devices_list: "{{ ceph_data_partition_to_erase_path.stdout_lines +
+ ceph_lockbox_partition_to_erase_path.stdout_lines +
+ ceph_block_partition_to_erase_path.stdout_lines +
+ ceph_journal_partition_to_erase_path.stdout_lines +
+ ceph_db_partition_to_erase_path.stdout_lines +
+ ceph_wal_partition_to_erase_path.stdout_lines }}"
+
+ - name: resolve parent device
+ shell: echo /dev/$(lsblk -no pkname "{{ item }}")
+ register: tmp_resolved_parent_device
+ with_items:
+ - "{{ combined_devices_list }}"
+
+ - name: set_fact resolved_parent_device
+ set_fact:
+ resolved_parent_device: "{{ tmp_resolved_parent_device.results | map(attribute='stdout') | list | unique }}"
+
- name: zap ceph journal/block db/block wal partitions
shell: |
# if the disk passed is a raw device AND the boot system disk
- if echo "{{ item }}" | egrep -sq '/dev/([hsv]d[a-z]{1,2}|cciss/c[0-9]d[0-9]p|nvme[0-9]n[0-9]p){1,2}$' && parted -s $(echo "{{ item }}" | egrep -o '/dev/([hsv]d[a-z]{1,2}|cciss/c[0-9]d[0-9]p|nvme[0-9]n[0-9]p){1,2}') print | grep -sq boot; then
+ if parted -s "{{ item }}" print | grep -sq boot; then
echo "Looks like {{ item }} has a boot partition,"
echo "if you want to delete specific partitions point to the partition instead of the raw device"
echo "Do not use your system disk!"
exit 1
fi
- raw_device=$(echo "{{ item }}" | egrep -o '/dev/([hsv]d[a-z]{1,2}|cciss/c[0-9]d[0-9]|nvme[0-9]n[0-9]){1,2}')
- partition_nb=$(echo "{{ item }}" | egrep -o '[0-9]{1,2}$')
- sgdisk --delete $partition_nb $raw_device
+ sgdisk -Z "{{ item }}"
+ dd if=/dev/zero of="{{ item }}" bs=1M count=200
+ udevadm settle --timeout=600
with_items:
- - "{{ ceph_block_partition_to_erase_path.stdout_lines | default([]) }}"
- - "{{ ceph_journal_partition_to_erase_path.stdout_lines | default([]) }}"
- - "{{ ceph_db_partition_to_erase_path.stdout_lines | default([]) }}"
- - "{{ ceph_wal_partition_to_erase_path.stdout_lines | default([]) }}"
- when:
- - (ceph_block_partlabels.rc == 0 or ceph_journal_partlabels.rc == 0 or ceph_db_partlabels.rc == 0 or ceph_wal_partlabels.rc == 0)
+ - "{{ resolved_parent_device }}"
- name: purge ceph mon cluster