community.general.parted (8.5.0) — module

Configure block device partitions

Authors: Fabrizio Colonna (@ColOfAbRiX)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

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


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a new ext4 primary partition
  community.general.parted:
    device: /dev/sdb
    number: 1
    state: present
    fs_type: ext4
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove partition number 1
  community.general.parted:
    device: /dev/sdb
    number: 1
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a new primary partition with a size of 1GiB
  community.general.parted:
    device: /dev/sdb
    number: 1
    state: present
    part_end: 1GiB
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a new primary partition for LVM
  community.general.parted:
    device: /dev/sdb
    number: 2
    flags: [ lvm ]
    state: present
    part_start: 1GiB
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a new primary partition with a size of 1GiB at disk's end
  community.general.parted:
    device: /dev/sdb
    number: 3
    state: present
    fs_type: ext3
    part_start: -1GiB
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example on how to read info and reuse it in subsequent task
- name: Read device information (always use unit when probing)
  community.general.parted: device=/dev/sdb unit=MiB
  register: sdb_info
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove all partitions from disk
  community.general.parted:
    device: /dev/sdb
    number: '{{ item.num }}'
    state: absent
  loop: '{{ sdb_info.partitions }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Extend an existing partition to fill all available space
  community.general.parted:
    device: /dev/sdb
    number: "{{ sdb_info.partitions | length }}"
    part_end: "100%"
    resize: true
    state: present

Inputs

    
name:
    description:
    - Sets the name for the partition number (GPT, Mac, MIPS and PC98 only).
    type: str

unit:
    choices:
    - s
    - B
    - KB
    - KiB
    - MB
    - MiB
    - GB
    - GiB
    - TB
    - TiB
    - '%'
    - cyl
    - chs
    - compact
    default: KiB
    description:
    - 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 recommended to always specify a unit.
    type: str

align:
    choices:
    - cylinder
    - minimal
    - none
    - optimal
    - undefined
    default: optimal
    description:
    - Set alignment for newly created partitions. Use V(undefined) for parted default
      alignment.
    type: str

flags:
    description: A list of the flags that has to be set on the partition.
    elements: str
    type: list

label:
    choices:
    - aix
    - amiga
    - bsd
    - dvh
    - gpt
    - loop
    - mac
    - msdos
    - pc98
    - sun
    default: msdos
    description:
    - Disk label type or partition table to use.
    - If O(device) already contains a different label, it will be changed to O(label)
      and any previous partitions will be lost.
    - A O(name) must be specified for a V(gpt) partition table.
    type: str

state:
    choices:
    - absent
    - present
    - info
    default: info
    description:
    - Whether to create or delete a partition.
    - If set to V(info) the module will only return the device information.
    type: str

device:
    description:
    - The block device (disk) where to operate.
    - Regular files can also be partitioned, but it is recommended to create a loopback
      device using C(losetup) to easily access its partitions.
    required: true
    type: str

number:
    description:
    - The partition number being affected.
    - Required when performing any action on the disk, except fetching information.
    type: int

resize:
    default: false
    description:
    - Call C(resizepart) on existing partitions to match the size specified by O(part_end).
    type: bool
    version_added: 1.3.0
    version_added_collection: community.general

fs_type:
    description:
    - If specified and the partition does not exist, will set filesystem type to given
      partition.
    - Parameter optional, but see notes below about negative O(part_start) values.
    type: str
    version_added: 0.2.0
    version_added_collection: community.general

part_end:
    default: 100%
    description:
    - Where the partition will end as offset from the beginning of the disk, that is,
      the "distance" from the start of the disk. Negative numbers specify distance from
      the end of the disk.
    - The distance can be specified with all the units supported by parted (except compat)
      and it is case sensitive, for example V(10GiB), V(15%).
    type: str

part_type:
    choices:
    - extended
    - logical
    - primary
    default: primary
    description:
    - May be specified only with O(label=msdos) or O(label=dvh).
    - Neither O(part_type) nor O(name) may be used with O(label=sun).
    type: str

part_start:
    default: 0%
    description:
    - Where the partition will start as offset from the beginning of the disk, that is,
      the "distance" from the start of the disk. Negative numbers specify distance from
      the end of the disk.
    - The distance can be specified with all the units supported by parted (except compat)
      and it is case sensitive, for example V(10GiB), V(15%).
    - Using negative values may require setting of O(fs_type) (see notes).
    type: str

Outputs

partition_info:
  contains:
    disk:
      description: Generic device information.
      type: dict
    partitions:
      description: List of device partitions.
      type: list
    script:
      description: parted script executed by module
      type: str
  description: Current partition information
  returned: success
  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
    script: 'unit KiB print '
  type: complex