Ansible - parted module (create or remove partition)

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

The parted module can be used to create a remove a partition on a storage device. Let's say the /dev/sdb storage device has not yet been configured with a parition. The following playbook would create the /dev/sdb1 partition on the storage device, using all of the available storage on the disk for the new partition.

AVOID TROUBLE

The modification of a partition can only be done by root or a user or group that has been granted sudo access. Refer to beome / sudo to understand how to run a playbook as root or with become (sudo) permission.

---
- hosts: all
  tasks:
    - name: create the /dev/sdb1 partition
      parted:
        device: /dev/sdb
        number: 1
        part_start: "0%"
        part_end: "100%"
        state: present
...

 

Instead of using part_start: 0% and part_end: 100%, which uses all of the available space on the disk for the partition, you could specify the amount of space you want allocated for the partition, such as 1 GB.

---
- hosts: all
  tasks:
    - name: create a 1 GB /dev/sdb1 partition
      parted:
        device: /dev/sdb
        number: 1
        part_start: 1GiB
        state: present
...

 

The flags option can be used to set a partition type, such as setting a partition type to swap or LVM.

---
- hosts: all
  tasks:
    - name: create a 1 GB /dev/sdb2 swap partition
      parted:
        device: /dev/sdb
        number: 2
        part_start: 1GiB
        flags: [ swap ]
        state: present
...

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 1bebc in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |