githubixx.lvm
Ansible Role for LVM
This Ansible role installs the Linux Logical Volume Manager (LVM) and manages resources such as 'Volume Groups' (VG), 'Logical Volumes' (LV), file systems, and mount points.
Change Log
For updates and changes, see the CHANGELOG.
Role Variables
By default, no LVM resources are created. To create them, you can use the lvm_vgs key.
lvm_vgs: []
Example of Creating LVM Resources
- Create a Volume Group (VG) named
test-vg-01using the device/dev/vdb:
lvm_vgs:
- vgname: test-vg-01
pvs: /dev/vdb
state: present
Important Parameters
vgname: Name of the Volume Grouppvs: A list of devices to usestate: Should bepresentto create the VG orabsentto delete it (requiresforce: true).
- Create a VG called
test-vg-01using devices/dev/vdband/dev/vdc:
lvm_vgs:
- vgname: test-vg-01
pvs: /dev/vdb,/dev/vdc
state: present
Additional Parameters Supported
vg_optionspesizepv_options
Create Logical Volumes
Add a logical volume test-lv-01 that allocates 10% of the VG space:
lvm_vgs:
- vgname: test-vg-01
pvs: /dev/vdb
state: present
lvm_lvs:
- lvname: test-lv-01
size: 10%VG
state: present
Required Logical Volume Parameters
lvname: Name of the logical volumesize: Size of the logical volumestate:presentto create orabsentto delete (also requiresforce: true).
Creating a Filesystem
Create an ext4 filesystem on the logical volume:
lvm_vgs:
- vgname: test-vg-01
pvs: /dev/vdb
state: present
lvm_lvs:
- lvname: test-lv-01
size: 10%VG
state: present
fs:
type: ext4
state: present
Use the fs key to define the filesystem type. The filesystem will be created if it doesn't exist.
Mounting the Filesystem
Create a directory /mnt1 and mount the filesystem:
lvm_vgs:
- vgname: test-vg-01
pvs: /dev/vdb
state: present
lvm_lvs:
- lvname: test-lv-01
size: 10%VG
state: present
fs:
type: ext4
state: present
mountpoint:
state: mounted
path:
name: /mnt1
Additional Mountpoint Parameters
src: Specifies the source for the mountpath: Directory where the filesystem will be mounted
Unmount and Clean Up Example
To unmount a filesystem and delete it:
mountpoint:
state: absent
path:
name: /vg01lv01
Important Note on Deleting Resources
Deleting filesystems, logical volumes, or volume groups may result in data loss. Use state: absent with force: true to safely delete these resources.
Example for Unmounting and Deleting a VG
lvm_vgs:
- vgname: vg02
pvs: /dev/vdc
state: absent
force: true
lvm_lvs:
- lvname: vg02lv01
state: absent
force: true
Required Packages for Filesystems
To create filesystems, install additional packages like e2fsprogs for ext filesystems. Below is the list for various OS:
# For SuSE
additional_packages_suse:
- e2fsprogs
# For Debian
additional_packages_debian:
- e2fsprogs
# For Redhat
additional_packages_redhat:
- e2fsprogs
# For Archlinux
additional_packages_arch:
- e2fsprogs
Role Dependencies
This role depends on several Ansible modules:
TODO List
Features not implemented yet:
- Resize Volume Groups
- Shrink Logical Volumes
- Logical Volume Snapshots
- Resize Logical Volumes & Filesystems
Example Playbook
- Simple Example:
- hosts: your-host
roles:
- githubixx.lvm
- Example with Role Tag:
- hosts: your-host
roles:
- role: githubixx.lvm
tags: role-lvm
Testing
This role tests using Molecule, libvirt, and QEMU/KVM. For details, see the blog post on setting up testing.
To execute tests:
molecule converge -s kvm
To clean up:
molecule destroy -s kvm
License
This work is licensed under the GNU General Public License v3.0 or later.
Author Information
For more details, visit http://www.tauceti.blog.
ansible-galaxy install githubixx.lvm