community.general.lvm_pv module – Manage LVM Physical Volumes

Note

This module is part of the community.general collection (version 14.0.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.

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

New in community.general 11.0.0

Synopsis

  • Creates, resizes or removes LVM Physical Volumes.

Parameters

Parameter

Comments

allocatable

boolean

added in community.general 13.5.0

Whether the PV can be used for allocation of physical extents.

Managed using pvchange. LVM only supports this once the PV is part of a volume group; the module fails if the PV is still an orphan (not yet part of any volume group).

Choices:

  • false

  • true

dataalignment

string

added in community.general 13.5.0

Align the start of the PV data area to a multiple of this value, for example 1m.

Only applied when creating a new PV; cannot be changed afterwards.

device

path / required

Path to the block device to manage.

force

boolean

Force the operation.

When state=present (creating a PV), this uses pvcreate -f to force creation.

When state=absent (removing a PV), this uses pvremove -ff to force removal even if part of a volume group.

Choices:

  • false ← (default)

  • true

metadataignore

boolean

added in community.general 13.5.0

Whether metadata areas on the PV are ignored, meaning LVM does not store VG metadata on it.

Applied when creating a new PV, and enforced on existing PVs using pvchange.

Choices:

  • false

  • true

metadatasize

string

added in community.general 13.5.0

Approximate amount of space to reserve for VG metadata on the PV, for example 128k or 1m.

Only applied when creating a new PV; the metadata area size cannot be changed afterwards.

pvmetadatacopies

integer

added in community.general 13.5.0

Number of metadata areas to reserve on the PV for storing VG metadata.

Only applied when creating a new PV; cannot be changed afterwards.

Choices:

  • 0

  • 1

  • 2

resize

boolean

Resize PV to device size when state=present.

Choices:

  • false ← (default)

  • true

state

string

Control if the physical volume exists.

Choices:

  • "present" ← (default)

  • "absent"

tags

list / elements=string

added in community.general 13.5.0

List of tags that must be set on the PV.

Tags present on the PV but not listed here are removed; tags listed here but not yet present are added.

Managed using pvchange. LVM only supports tags once the PV is part of a volume group; the module fails if the PV is still an orphan (not yet part of any volume group).

zero

boolean

added in community.general 13.5.0

Control whether the first 4 sectors of the device are wiped when creating the PV.

Only applied when creating a new PV; has no effect on a PV that already exists.

Choices:

  • false

  • true

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

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

Notes

Note

  • Requires LVM2 utilities installed on the target system.

  • Device path must exist when creating a PV.

  • zero, metadatasize, dataalignment, and pvmetadatacopies only take effect when the PV is created; they are ignored for a PV that already exists.

  • metadataignore detection on an existing PV relies on comparing the number of metadata areas on the PV with the number in use, so it is only meaningful when the PV has at least one metadata area.

Examples

- name: Creating physical volume on /dev/sdb
  community.general.lvm_pv:
    device: /dev/sdb

- name: Creating and resizing (if needed) physical volume
  community.general.lvm_pv:
    device: /dev/sdb
    resize: true

- name: Removing physical volume that is not part of any volume group
  community.general.lvm_pv:
    device: /dev/sdb
    state: absent

- name: Force removing physical volume that is already part of a volume group
  community.general.lvm_pv:
    device: /dev/sdb
    force: true
    state: absent

- name: Creating a physical volume with custom metadata layout
  community.general.lvm_pv:
    device: /dev/sdb
    metadatasize: 128m
    dataalignment: 1m
    pvmetadatacopies: 2

- name: Creating a physical volume without wiping existing signatures and with no metadata areas
  community.general.lvm_pv:
    device: /dev/sdb
    zero: false
    pvmetadatacopies: 0

- name: Setting tags and excluding a physical volume from allocation (PV must already be part of a VG)
  community.general.lvm_pv:
    device: /dev/sdb
    allocatable: false
    tags:
      - fast_disks
      - site_a

Authors

  • Klention Mali (@klention)