]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
purge-cluster: use parted ansible module
authorDimitri Savineau <dsavinea@redhat.com>
Tue, 12 Jan 2021 20:47:42 +0000 (15:47 -0500)
committerGuillaume Abrioux <gabrioux@redhat.com>
Wed, 3 Feb 2021 07:28:22 +0000 (08:28 +0100)
Instead of doing some scripting via the shell module, we can use the
parted ansible module to check the boot flag on partitions.

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
infrastructure-playbooks/purge-cluster.yml

index c7ad96e96599329c10009b97fcbdf50b79b8837a..023d502ff205237e3c94a3a81ec4b0eec41bee62 100644 (file)
     changed_when: false
     with_items: "{{ combined_devices_list }}"
 
+  - name: check parent device partition
+    parted:
+      device: "/dev/{{ item }}"
+    loop: "{{ resolved_parent_device }}"
+    register: parted_info
+
+  - name: fail if there is a boot partition on the device
+    fail:
+      msg: "{{ item.item }} has a boot partition"
+    loop: "{{ parted_info.results }}"
+    when: "'boot' in (item.partitions | map(attribute='flags') | list | flatten)"
+
   - name: zap ceph journal/block db/block wal partitions  # noqa 306
     shell: |
-      # if the disk passed is a raw device AND the boot system disk
-      if parted -s /dev/"{{ item }}" print | grep -sq boot; then
-        echo "Looks like /dev/{{ 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
       sgdisk -Z --clear --mbrtogpt -g -- /dev/"{{ item }}"
       dd if=/dev/zero of=/dev/"{{ item }}" bs=1M count=200
       parted -s /dev/"{{ item }}" mklabel gpt