Automate Partitions, LVM and File Systems
The `storage` group holds node1 (dev), node2 (test) and node3 (prod). node2 has an empty 2 GiB disk `/dev/vdb`; node3's disk already carries the volume group `research`; node1 has no spare disk at all. Exam-style: one playbook must cope with all three. Collections are installed in `~/ansible/collections`.
Tasks
- Write ~/ansible/partition.yml for test: on /dev/vdb create partition 1 (from the start to 1000 MiB, flag lvm) and partition 2 (1000 MiB to 1500 MiB).
- Write ~/ansible/vg.yml: on test, create the volume group research on /dev/vdb1.
- Write ~/ansible/lv.yml for the whole storage group: create LV data of 1500 MiB in VG research. If the VG is too small, print Could not create a logical volume of that size and create it with 800 MiB instead. Where research does not exist, print Volume group does not exist and create nothing.
- Write ~/ansible/fs.yml: wherever LV research/data exists, put an XFS file system on it and mount it persistently on /mnt/data. Hosts without the LV must be left alone.
- Write ~/ansible/archivefs.yml: on test, format /dev/vdb2 as ext4 and mount it persistently on /mnt/archive.