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 like10G,512M,100%FREE,50%VG,50%PVS,50%ORIGIN. For an LV that already exists,N%FREEsets 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, use100%VGif it is the only LV, or an absolute size. - Type: String.
- Mandatory (for state=present). Absolute size of the LV (relative sizes with
-
fstype:- Optional. Filesystem type. The role installs the tools for
xfsandext2/ext3/ext4; for any other type, install them beforehand. Note that on RHEL 10,mkfs.xfsrefuses to create an XFS file system smaller than 300 MB. - Type: String.
- Default:
'xfs'
- Optional. Filesystem type. The role installs the tools for
-
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
- Optional. Allow shrinking the LV. Also needs
-
force:- Optional. Has to be
trueto shrink (together withshrink: 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
- Optional. Has to be
-
mount_path:- Optional. Mount point path. If specified, the directory will be created, the LV will be mounted, and on hosts with SELinux enabled,
restoreconwill be run automatically on the mount path. - Type: String.
- Optional. Mount point path. If specified, the directory will be created, the LV will be mounted, and on hosts with SELinux enabled,
-
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.
presentorabsent. - Type: String.
- Default:
'present'
- Optional.
-
-
Type: List of dictionaries.
- Default:
[]
lvm__vgs__host_var / lvm__vgs__group_var
- List of volume groups to manage. PVs listed in
pvsare 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.
- Mandatory (for state=present). List of physical volume device paths to include in the VG. PVs are automatically created (
-
growpart:- Optional. If
true, automatically runsgrowparton 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 providinggrowpart(cloud-utils-growparton RHEL,cloud-guest-utilson Debian and Ubuntu). - Type: Bool.
- Default:
false
- Optional. If
-
pesize:- Optional. Physical extent size (e.g.,
4,128K). - Type: String.
- Default:
4
- Optional. Physical extent size (e.g.,
-
force:- Optional. Force removal of VG even if LVs exist. Only used when
state: absent. - Type: Bool.
- Default:
false
- Optional. Force removal of VG even if LVs exist. Only used when
-
state:- Optional.
presentorabsent. - Type: String.
- Default:
'present'
- Optional.
-
-
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