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 (on host that executes 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/.

Options

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

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 Return Values, the following are the fields unique to this module:

name description returned type sample
partition_info
Current partition information
success complex
contains:
name description returned type sample
device
Generic device information.
dict
sample
partitions
List of device partitions.
list

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.

Status

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

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.

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