parted - Configure block device partitions

New in version 2.3.

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
    Choices:
  • none
  • cylinder
  • minimal
  • optimal
Set alignment for newly created partitions.
device
required
The block device (disk) where to operate.
flags
A list of the flags that has to be set on the partition.
label
    Choices:
  • aix
  • amiga
  • bsd
  • dvh
  • gpt
  • loop
  • mac
  • msdos
  • pc98
  • sun
Creates a new disk label.
name
Sets the name for the partition number (GPT, Mac, MIPS and PC98 only).
number
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 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 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
    Choices:
  • primary
  • extended
  • logical
Is one of 'primary', 'extended' or 'logical' and 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
    Choices:
  • present
  • absent
  • info
If to create or delete a partition. If set to info the module will only return the device information.
unit
    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

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

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

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

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

# 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 }}"

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

device
dict
Generic device information.

sample

partitions
list
List of device partitions.



Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Author

  • Fabrizio Colonna (@ColOfAbRiX)

Hint

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

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.5/modules/parted_module.html