# Delete Partition Table

**URL:** <https://forum.ansible.com/t/delete-partition-table/28371>\
**Category:** Ansible Project\
**Created:** [August 20, 2018, 4:59pm UTC](https://forum.ansible.com/t/delete-partition-table/28371 "2018-08-20T16:59:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmartin](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@dmartin](https://forum.ansible.com/u/dmartin)\
**Post date:** [August 20, 2018, 4:59pm UTC](https://forum.ansible.com/t/delete-partition-table/28371/1 "2018-08-20T16:59:08Z")

</div>

Hi everyone!

I’m trying to clear a partition table. That is, delete all partitions. I don’t see how to do that with the parted module.

Thanks!  
-Dylab

---

<div class="post-metadata">

**Author:** ![Stephane\_Emilien](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@Stephane\_Emilien](https://forum.ansible.com/u/Stephane_Emilien)\
**Post date:** [August 25, 2018, 12:21pm UTC](https://forum.ansible.com/t/delete-partition-table/28371/2 "2018-08-25T12:21:19Z")

</div>

Hi,

Please note that the current state fo the ‘parted’ module is mainly focused around partition management (mostly creation and deletion)  
It supports clearing/recreating the partition table but will only work if there’s an actual _change of state_ on a partition.

You can use either method for your case:

**Delete all partitions on the block device:**  
As the doc says - [https://docs.ansible.com/ansible/2.5/modules/parted\_module.html](https://docs.ansible.com/ansible/2.5/modules/parted_module.html)

`

# Read device information (always use unit when probing)

- parted: device=/dev/sdb unit=MiB  
register: sdb\_info

# Remove all partitions from disk

- parted:  
device: /dev/sdb  
number: “{{ item.num }}”  
state: absent  
with\_items:
- “{{ sdb\_info.partitions }}”  
`

**Re-create the partition table:**  
If you want to clear the partition table itself, you’ll need to switch it to another type and back to the desired one (msdos,gpt,bsd,sun,etc…)

> > >

`

- parted:  
device: /dev/sdb  
label: “{{ item.label }}”  
number: “{{ item.num }}”  
state: “{{ item.state}}”  
with\_items:

- { num: 1, label: amiga, state: absent } # Remove the first partition and create a new ‘amiga’ partition table

- { num: 1, label: gpt, state: present } # Necessary step, recreates the partition table with a partition

- { num: 1, label: gpt, state: absent } # This removes the newly created partition  
`

- SDE
