Skip to content

Ansible Role linuxfabrik.lfops.lvm

This role manages LVM (Logical Volume Manager) including partitions, physical volumes, volume groups, and logical volumes. It can also create filesystems and mount the logical volumes.

Available since LFOps 6.0.0.

Tags

lvm

  • Runs all LVM tasks.
  • Triggers: none.

lvm:filesystem

  • Installs the tools for the file systems in use, creates filesystems on logical volumes.
  • Triggers: none.

lvm:info

  • Displays current LVM state (lsblk, df, pvs, vgs, lvs).
  • Triggers: none.

lvm:lv

  • Creates/extends/removes logical volumes.
  • Triggers: none.

lvm:mount

  • Mounts volumes, sets owner and mode of their mount directories, restorecon.
  • Triggers: none.

lvm:vg

  • Installs lvm2 and growpart, runs growpart (if enabled), creates/resizes PVs, creates/extends/removes VGs.
  • Triggers: none.

Optional Role Variables

lvm__lvs__host_var / lvm__lvs__group_var

  • List of logical volumes to manage.
  • Subkeys:

    • name:

      • Mandatory. The logical volume name.
      • Type: String.
    • vg:

      • Mandatory. The volume group name.
      • Type: String.
    • size:

      • Mandatory (for state=present). Absolute size of the LV (relative sizes with + or - prefix are not allowed). Supports formats like 10G, 512M, 100%FREE, 50%VG, 50%PVS, 50%ORIGIN. For an LV that already exists, N%FREE sets it to N% of the space that is free in the VG right now, not to its current size plus that space. To have an existing LV fill its VG, use 100%VG if it is the only LV, or an absolute size.
      • Type: String.
    • fstype:

      • Optional. Filesystem type. The role installs the tools for xfs and ext2 / ext3 / ext4; for any other type, install them beforehand. Note that on RHEL 10, mkfs.xfs refuses to create an XFS file system smaller than 300 MB.
      • Type: String.
      • Default: 'xfs'
    • resizefs:

      • Optional. Resize the filesystem together with the LV.
      • Type: Bool.
      • Default: true
    • shrink:

      • Optional. Allow shrinking the LV. Also needs force: true. XFS cannot be shrunk.
      • Type: Bool.
      • Default: false
    • force:

      • Optional. Has to be true to shrink (together with shrink: true) or to remove (state: absent) the LV. The role refuses both otherwise, so that no file system is destroyed by mistake.
      • Type: Bool.
      • Default: false
    • mount_path:

      • Optional. Mount point path. If specified, the directory will be created, the LV will be mounted, and on hosts with SELinux enabled, restorecon will be run automatically on the mount path.
      • Type: String.
    • mount_opts:

      • Optional. Mount options.
      • Type: String.
      • Default: 'defaults'
    • mount_owner:

      • Optional. Owner of the mount directory.
      • Type: String.
      • Default: 'root'
    • mount_group:

      • Optional. Group of the mount directory.
      • Type: String.
      • Default: 'root'
    • mount_mode:

      • Optional. Mode of the mount directory.
      • Type: String.
      • Default: 0o0755
    • state:

      • Optional. present or absent.
      • Type: String.
      • Default: 'present'
  • Type: List of dictionaries.

  • Default: []

lvm__vgs__host_var / lvm__vgs__group_var

  • List of volume groups to manage. PVs listed in pvs are automatically created and resized.
  • Subkeys:

    • name:

      • Mandatory. The volume group name.
      • Type: String.
    • pvs:

      • Mandatory (for state=present). List of physical volume device paths to include in the VG. PVs are automatically created (pvcreate) and resized (pvresize) before the VG is created/extended.
      • Type: List.
    • growpart:

      • Optional. If true, automatically runs growpart on partition-based PVs (e.g., /dev/vda3) before resizing. The partition device and number are auto-detected from the PV path. The role installs the package providing growpart (cloud-utils-growpart on RHEL, cloud-guest-utils on Debian and Ubuntu).
      • Type: Bool.
      • Default: false
    • pesize:

      • Optional. Physical extent size (e.g., 4, 128K).
      • Type: String.
      • Default: 4
    • force:

      • Optional. Force removal of VG even if LVs exist. Only used when state: absent.
      • Type: Bool.
      • Default: false
    • state:

      • Optional. present or absent.
      • Type: String.
      • Default: 'present'
  • Type: List of dictionaries.

  • Default: []

Example:

# optional
lvm__lvs__host_var:
  - name: 'data'
    vg: 'data'
    size: '100G'
    fstype: 'xfs'
    mount_path: '/data'
    mount_opts: 'nodev,noexec,nosuid'
lvm__vgs__host_var:
  - name: 'data'
    pvs:
      - '/dev/vdb'

to extend an existing LV:

lvm__lvs__host_var:
  - name: 'root'
    vg: 'rl'
    size: '25G'

to create a /data/ mount on a separate device (/dev/vdb):

lvm__lvs__host_var:
  - name: 'data'
    vg: 'data'
    size: '100%FREE'
    fstype: 'xfs'
    mount_path: '/data'
    mount_opts: 'nodev,noexec,nosuid'
lvm__vgs__host_var:
  - name: 'data'
    pvs:
      - '/dev/vdb'

to create a /data/ mount on an existing volume group:

lvm__lvs__host_var:
  - name: 'data'
    vg: 'rl'
    size: '100%FREE'
    fstype: 'xfs'
    mount_path: '/data'
    mount_opts: 'nodev,noexec,nosuid'
lvm__vgs__host_var:
  # pvresize and growpart
  - name: 'rl'
    pvs:
      - '/dev/vda3'
    growpart: true

to extend an existing volume group with an additional device (/dev/vdb). pvs is the complete list of PVs of the VG, so also list the existing ones (see pvs on the host). PVs that are not listed are removed from the VG:

lvm__vgs__host_var:
  - name: 'rl'
    pvs:
      - '/dev/vda3'
      - '/dev/vdb'

grow a partition:

lvm__vgs__host_var:
  - name: 'rl'
    pvs:
      - '/dev/vda3'
    growpart: true

License

The Unlicense

Author Information

Linuxfabrik GmbH, Zurich