Lets say you have 100 nodes and 1 control nodes.
100 nodes is mixed of some that have a VG called databin and some don't
and
100 nodes is mixed of various size of VG databin
Create a logical volume with specific size, if the volume group
doesn't have enough size output a message and use another size.
( LV name = dbdata and size 2.5G if VG databin have sufficient size or fall back to 1G )
If volume group doesn't exist exit with output message
( if VG databin not there, we skip )
If logical volume created format and mount to disk
( if dbdata LV created, format with ext4 and mount to /db )
--sample Playbook using Block and Fail ( error handling )--
---
- name: Setup LVM
hosts: all
tasks:
- name: Check for databin VG
fail:
msg: VG databin does not exist
when:
- ansible_lvm['vgs']['databin'] is not defined
- name: Create LVM and Filesystem and Mount
block:
- name: Check for databin VG Size of 2500MiB
fail:
msg: Could not create LV with 2500MiB size
when:
- ansible_lvm['vgs']['databin']['size_g'] < "2.50"
- name: Create 2500MiB LVM on databin VG
lvol:
lv: dbdata
vg: databin
size: "2532"
rescue:
- name: Fall back and Create 1024MiB LVM on databin VG
lvol:
size: "1024"
vg: databin
lv: dbdata
always:
- name: Set Filesystem
filesystem:
dev: /dev/databin/dbdata
fstype: ext4
- name: Mount LV
mount:
path: /db
src: /dev/databin/dbdata
fstype: ext4
state: present