community.general.parted – Configure block device partitions¶
Note
This plugin is part of the community.general collection (version 1.3.6).
To install it use: ansible-galaxy collection install community.general
.
To use it in a playbook, specify: community.general.parted
.
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
align option (except ‘undefined’) requires parted 2.1 and above
If the version of parted is below 3.1, it requires a Linux version running the sysfs file system
/sys/
.
Parameters¶
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.Negative
part_start
start values were rejected iffs_type
was not given. This bug was fixed in parted 3.2.153. If you want to use negativepart_start
, specifyfs_type
as well or make sure your system contains newer parted.
Examples¶
- name: Create a new ext4 primary partition
community.general.parted:
device: /dev/sdb
number: 1
state: present
fs_type: ext4
- name: Remove partition number 1
community.general.parted:
device: /dev/sdb
number: 1
state: absent
- name: Create a new primary partition with a size of 1GiB
community.general.parted:
device: /dev/sdb
number: 1
state: present
part_end: 1GiB
- name: Create a new primary partition for LVM
community.general.parted:
device: /dev/sdb
number: 2
flags: [ lvm ]
state: present
part_start: 1GiB
- 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
# 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
- name: Remove all partitions from disk
community.general.parted:
device: /dev/sdb
number: '{{ item.num }}'
state: absent
loop: '{{ sdb_info.partitions }}'
- 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
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
Fabrizio Colonna (@ColOfAbRiX)