ansible / ansible.builtin / v2.6.20 / module / parted Configure block device partitions | "added in version" 2.3 of ansible.builtin" Authors: Fabrizio Colonna (@ColOfAbRiX) preview | supported by communityansible.builtin.parted (v2.6.20) — module
pip
Install with pip install ansible==2.6.20
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.
# 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 }}"
name: description: - Sets the name for the partition number (GPT, Mac, MIPS and PC98 only). 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 always recommended to specify a unit. align: choices: - none - cylinder - minimal - optimal default: optimal description: Set alignment for newly created partitions. flags: description: 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 default: msdos description: Creates a new disk label. state: choices: - present - absent - info default: info description: - If to create or delete a partition. If set to C(info) the module will only return the device information. device: description: The block device (disk) where to operate. required: true number: description: - 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% description: - 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. C(10GiB), C(15%). part_type: choices: - primary - extended - logical default: primary description: - 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. 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. The distance can be specified with all the units supported by parted (except compat) and it is case sensitive. E.g. C(10GiB), C(15%).
partition_info: contains: device: description: Generic device information. type: dict partitions: description: List of device partitions. type: list sample: "{\n \"disk\": {\n \"dev\": \"/dev/sdb\",\n \"logical_block\":\ \ 512,\n \"model\": \"VMware Virtual disk\",\n \"physical_block\": 512,\n\ \ \"size\": 5.0,\n \"table\": \"msdos\",\n \"unit\": \"gib\"\n },\n\ \ \"partitions\": [{\n \"begin\": 0.0,\n \"end\": 1.0,\n \"flags\"\ : [\"boot\", \"lvm\"],\n \"fstype\": \"\",\n \"name\": \"\",\n \"num\"\ : 1,\n \"size\": 1.0\n }, {\n \"begin\": 1.0,\n \"end\": 5.0,\n \ \ \"flags\": [],\n \"fstype\": \"\",\n \"name\": \"\",\n \"num\":\ \ 2,\n \"size\": 4.0\n }]\n}\n" description: Current partition information returned: success type: complex