parted – Configure block device partitions

Synopsis

  • This module allows configuring block device partition using the parted command line tool. For a full description of the fields and the options check the GNU parted manual.

Requirements

The below requirements are needed on the host that executes this module.

  • This module requires parted version 1.8.3 and above.

  • If the version of parted is below 3.1, it requires a Linux version running the sysfs file system /sys/.

Parameters

Parameter Choices/Defaults Comments
align
string
    Choices:
  • cylinder
  • minimal
  • none
  • optimal ←
Set alignment for newly created partitions.
device
string / required
The block device (disk) where to operate.
flags
list
A list of the flags that has to be set on the partition.
label
string
    Choices:
  • aix
  • amiga
  • bsd
  • dvh
  • gpt
  • loop
  • mac
  • msdos ←
  • pc98
  • sun
Creates a new disk label.
name
string
Sets the name for the partition number (GPT, Mac, MIPS and PC98 only).
number
integer
The number of the partition to work with or the number of the partition that will be created.
Required when performing any action on the disk, except fetching information.
part_end
string
Default:
"100%"
Where the partition will end as offset from the beginning of the disk, that is, the "distance" from the start of the disk.
The distance can be specified with all the units supported by parted (except compat) and it is case sensitive, e.g. 10GiB, 15%.
part_start
string
Default:
"0%"
Where the partition will start as offset from the beginning of the disk, that is, the "distance" from the start of the disk.
The distance can be specified with all the units supported by parted (except compat) and it is case sensitive, e.g. 10GiB, 15%.
part_type
string
    Choices:
  • extended
  • logical
  • primary ←
May be specified only with 'msdos' or 'dvh' partition tables.
A name must be specified for a 'gpt' partition table.
Neither part_type nor name may be used with a 'sun' partition table.
state
string
    Choices:
  • absent
  • present
  • info ←
Whether to create or delete a partition.
If set to info the module will only return the device information.
unit
string
    Choices:
  • s
  • B
  • KB
  • KiB ←
  • MB
  • MiB
  • GB
  • GiB
  • TB
  • TiB
  • %
  • cyl
  • chs
  • compact
Selects the current default unit that Parted will use to display locations and capacities on the disk and to interpret those given by the user if they are not suffixed by an unit.
When fetching information about a disk, it is always recommended to specify a unit.

Notes

Note

  • When fetching information about a new disk and when the version of parted installed on the system is before version 3.1, the module queries the kernel through /sys/ to obtain disk information. In this case the units CHS and CYL are not supported.

Examples

- name: Create a new primary partition
  parted:
    device: /dev/sdb
    number: 1
    state: present

- name: Remove partition number 1
  parted:
    device: /dev/sdb
    number: 1
    state: absent

- name: Create a new primary partition with a size of 1GiB
  parted:
    device: /dev/sdb
    number: 1
    state: present
    part_end: 1GiB

- name: Create a new primary partition for LVM
  parted:
    device: /dev/sdb
    number: 2
    flags: [ lvm ]
    state: present
    part_start: 1GiB

# Example on how to read info and reuse it in subsequent task
- name: Read device information (always use unit when probing)
  parted: device=/dev/sdb unit=MiB
  register: sdb_info

- name: Remove all partitions from disk
  parted:
    device: /dev/sdb
    number: '{{ item.num }}'
    state: absent
  loop: '{{ sdb_info.partitions }}'

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
partition_info
complex
success
Current partition information

Sample:
{'disk': {'dev': '/dev/sdb', 'logical_block': 512, 'model': 'VMware Virtual disk', 'physical_block': 512, 'size': 5.0, 'table': 'msdos', 'unit': 'gib'}, 'partitions': [{'begin': 0.0, 'end': 1.0, 'flags': ['boot', 'lvm'], 'fstype': '', 'name': '', 'num': 1, 'size': 1.0}, {'begin': 1.0, 'end': 5.0, 'flags': [], 'fstype': '', 'name': '', 'num': 2, 'size': 4.0}]}
 
device
dictionary
Generic device information.

 
partitions
list
List of device partitions.



Status

Authors

  • Fabrizio Colonna (@ColOfAbRiX)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.