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

  1. Create a Volume Group (VG) named test-vg-01 using the device /dev/vdb:
lvm_vgs:
  - vgname: test-vg-01
    pvs: /dev/vdb
    state: present

Important Parameters

  • vgname: Name of the Volume Group
  • pvs: A list of devices to use
  • state: Should be present to create the VG or absent to delete it (requires force: true).
  1. Create a VG called test-vg-01 using devices /dev/vdb and /dev/vdc:
lvm_vgs:
  - vgname: test-vg-01
    pvs: /dev/vdb,/dev/vdc
    state: present

Additional Parameters Supported

  • vg_options
  • pesize
  • pv_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 volume
  • size: Size of the logical volume
  • state: present to create or absent to delete (also requires force: 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 mount
  • path: 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

  1. Simple Example:
- hosts: your-host
  roles:
    - githubixx.lvm
  1. 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.

Informazioni sul progetto

Manage Linux Logical Volume Manager resources

Installa
ansible-galaxy install githubixx.lvm
Licenza
gpl-3.0
Download
1.8k
Proprietario
Senior System Engineer - Python, Go, Cloud, Kubernetes, Commodore, Retro, 80's ;-)