• Blog
  • Ansible community forum
  • Documentation
Ansible Logo
Ansible Community Documentation
Ansible

Ansible getting started

  • Getting started with Ansible
  • Getting started with Execution Environments

Installation, Upgrade & Configuration

  • Installation Guide
  • Ansible Porting Guides

Using Ansible

  • Building Ansible inventories
  • Using Ansible command line tools
  • Using Ansible playbooks
  • Protecting sensitive data with Ansible vault
  • Using Ansible modules and plugins
  • Using Ansible collections
  • Using Ansible on Windows, BSD, and z/OS UNIX
  • Ansible tips and tricks

Contributing to Ansible

  • Ansible Community Guide
  • Ansible Collections Contributor Guide
  • ansible-core Contributors Guide
  • Advanced Contributor Guide
  • Ansible documentation style guide

Extending Ansible

  • Developer Guide

Common Ansible Scenarios

  • Legacy Public Cloud Guides

Network Automation

  • Network Getting Started
  • Network Advanced Topics
  • Network Developer Guide

Ansible Galaxy

  • Galaxy User Guide
  • Galaxy Developer Guide

Reference & Appendices

  • Collection Index
    • Collections in the Amazon Namespace
    • Collections in the Ansible Namespace
    • Collections in the Arista Namespace
    • Collections in the Awx Namespace
    • Collections in the Azure Namespace
    • Collections in the Check_point Namespace
    • Collections in the Chocolatey Namespace
    • Collections in the Cisco Namespace
    • Collections in the Cloud Namespace
    • Collections in the Cloudscale_ch Namespace
    • Collections in the Community Namespace
      • Community.Aws
      • Community.Ciscosmb
      • Community.Crypto
      • Community.Digitalocean
      • Community.Dns
      • Community.Docker
      • Community.General
        • Description
        • Communication
        • Changelog
        • Guides
        • Cloud Guides
        • Developer Guides
        • Plugin Index
      • Community.Grafana
      • Community.Hashi_Vault
      • Community.Hrobot
      • Community.Library_Inventory_Filtering_V1
      • Community.Libvirt
      • Community.Mongodb
      • Community.Mysql
      • Community.Network
      • Community.Okd
      • Community.Postgresql
      • Community.Proxysql
      • Community.Rabbitmq
      • Community.Routeros
      • Community.Sap_Libs
      • Community.Sops
      • Community.Vmware
      • Community.Windows
      • Community.Zabbix
    • Collections in the Containers Namespace
    • Collections in the Cyberark Namespace
    • Collections in the Dellemc Namespace
    • Collections in the F5networks Namespace
    • Collections in the Fortinet Namespace
    • Collections in the Frr Namespace
    • Collections in the Gluster Namespace
    • Collections in the Google Namespace
    • Collections in the Grafana Namespace
    • Collections in the Hetzner Namespace
    • Collections in the Hitachivantara Namespace
    • Collections in the Hpe Namespace
    • Collections in the Ibm Namespace
    • Collections in the Ieisystem Namespace
    • Collections in the Infinidat Namespace
    • Collections in the Infoblox Namespace
    • Collections in the Inspur Namespace
    • Collections in the Junipernetworks Namespace
    • Collections in the Kaytus Namespace
    • Collections in the Kubernetes Namespace
    • Collections in the Kubevirt Namespace
    • Collections in the Lowlydba Namespace
    • Collections in the Mellanox Namespace
    • Collections in the Microsoft Namespace
    • Collections in the Netapp Namespace
    • Collections in the Netapp_eseries Namespace
    • Collections in the Netbox Namespace
    • Collections in the Ngine_io Namespace
    • Collections in the Openstack Namespace
    • Collections in the Openvswitch Namespace
    • Collections in the Ovirt Namespace
    • Collections in the Purestorage Namespace
    • Collections in the Sensu Namespace
    • Collections in the Servicenow Namespace
    • Collections in the Splunk Namespace
    • Collections in the T_systems_mms Namespace
    • Collections in the Telekom_mms Namespace
    • Collections in the Theforeman Namespace
    • Collections in the Vmware Namespace
    • Collections in the Vultr Namespace
    • Collections in the Vyos Namespace
    • Collections in the Wti Namespace
  • Indexes of all modules and plugins
  • Playbook Keywords
  • Return Values
  • Ansible Configuration Settings
  • Controlling how Ansible behaves: precedence rules
  • YAML Syntax
  • Python 3 Support
  • Interpreter Discovery
  • Releases and maintenance
  • Testing Strategies
  • Sanity Tests
  • Frequently Asked Questions
  • Glossary
  • Ansible Reference: Module Utilities
  • Special Variables
  • Red Hat Ansible Automation Platform
  • Ansible Automation Hub
  • Logging Ansible output

Roadmaps

  • Ansible Roadmap
  • ansible-core Roadmaps




Ansible
  • Collection Index
  • Collections in the Community Namespace
  • Community.General
  • community.general.parted module – Configure block device partitions
  • Edit on GitHub

'; // Create a banner if we're not on the official docs site if (location.host == "docs.testing.ansible.com") { document.write('
' + '

This is the testing site for Ansible Documentation. Unless you are reviewing pre-production changes, please visit the official documentation website.

' + '
'); } // Create a banner current_url_path = window.location.pathname; var important = false; var msg = '

'; if (startsWith(current_url_path, "/ansible-core/")) { msg += 'You are reading documentation for Ansible Core, which contains no plugins except for those in ansible.builtin. For documentation of the Ansible package, go to the latest documentation.'; } else if (startsWithOneOf(current_url_path, ["/ansible/latest/", "/ansible/11/"])) { /* temp extra banner to advertise something */ banner += extra_banner; msg += 'This is the latest (stable) Ansible community documentation. For Red Hat Ansible Automation Platform subscriptions, see Life Cycle for version details.'; } else if (startsWith(current_url_path, "/ansible/2.9/")) { msg += 'You are reading the latest Red Hat released version of the Ansible documentation. Community users can use this version, or select latest from the version selector to the left for the most recent community version.'; } else if (startsWith(current_url_path, "/ansible/devel/")) { /* temp extra banner to advertise something */ banner += extra_banner; msg += 'You are reading the devel version of the Ansible documentation - this version is not guaranteed stable. Use the version selection to the left if you want the latest (stable) released version.'; } else { msg += 'You are reading an older version of the Ansible documentation. Use the version selection to the left if you want the latest (stable) released version.'; /* temp extra banner to advertise something - this is for testing*/ banner += extra_banner; } msg += '

'; banner += '
'; banner += important ? '
' : ''; banner += msg; banner += important ? '
' : ''; banner += '
'; document.write(banner);

community.general.parted module – Configure block device partitions

Note

This module is part of the community.general collection (version 10.7.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.parted.

  • Synopsis

  • Requirements

  • Parameters

  • Attributes

  • Notes

  • Examples

  • Return Values

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.

  • Option align (except undefined) requires parted 2.1 or above.

  • If the version of parted is below 3.1, it requires a Linux version running the sysfs file system /sys/.

  • Requires the resizepart command when using the resize parameter.

Parameters

Parameter

Comments

align

string

Set alignment for newly created partitions. Use undefined for parted default alignment.

Choices:

  • "cylinder"

  • "minimal"

  • "none"

  • "optimal" ← (default)

  • "undefined"

device

string / required

The block device (disk) where to operate.

Regular files can also be partitioned, but it is recommended to create a loopback device using losetup to easily access its partitions.

flags

list / elements=string

A list of the flags that has to be set on the partition.

fs_type

string

added in community.general 0.2.0

If specified and the partition does not exist, will set filesystem type to given partition.

Parameter optional, but see notes below about negative part_start values.

label

string

Disk label type or partition table to use.

If device already contains a different label, it will be changed to label and any previous partitions will be lost.

A name must be specified for a gpt partition table.

Choices:

  • "aix"

  • "amiga"

  • "bsd"

  • "dvh"

  • "gpt"

  • "loop"

  • "mac"

  • "msdos" ← (default)

  • "pc98"

  • "sun"

name

string

Sets the name for the partition number (GPT, Mac, MIPS and PC98 only).

number

integer

The partition number being affected.

Required when performing any action on the disk, except fetching information.

part_end

string

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 10GiB, 15%.

Default: "100%"

part_start

string

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 10GiB, 15%.

Using negative values may require setting of fs_type (see notes).

Default: "0%"

part_type

string

May be specified only with label=msdos or label=dvh.

Neither part_type nor name may be used with label=sun.

Choices:

  • "extended"

  • "logical"

  • "primary" ← (default)

resize

boolean

added in community.general 1.3.0

Call resizepart on existing partitions to match the size specified by part_end.

Choices:

  • false ← (default)

  • true

state

string

Whether to create or delete a partition.

If set to info the module will only return the device information.

Choices:

  • "absent"

  • "present"

  • "info" ← (default)

unit

string

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.

Choices:

  • "s"

  • "B"

  • "KB"

  • "KiB" ← (default)

  • "MB"

  • "MiB"

  • "GB"

  • "GiB"

  • "TB"

  • "TiB"

  • "%"

  • "cyl"

  • "chs"

  • "compact"

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

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 if fs_type was not given. This bug was fixed in parted 3.2.153. If you want to use negative part_start, specify fs_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:

Key

Description

partition_info

complex

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

disk

dictionary

Generic device information.

Returned: success

partitions

list / elements=string

List of device partitions.

Returned: success

script

string

Parted script executed by module.

Returned: success

Authors

  • Fabrizio Colonna (@ColOfAbRiX)

Collection links

  • Issue Tracker
  • Repository (Sources)
  • Ask for help
  • Submit a bug report
  • Request a feature
  • Communication
Previous Next

© Copyright Ansible project contributors. Last updated on Jun 05, 2025.