From 54ad68b5bb82da6b8fc557ab3e728da81bffe047 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 29 Jun 2024 07:27:59 -0500 Subject: [PATCH] datavol: Playbook to provision a data volume The `datavol.yml` playbook can provision one or more data volumes on a managed node, using the definitions in the `data_volumes` variable. This variable must contain a list of dictionaries with the following keys: * `dev`: The block device where the data volume is stored (e.g. `/dev/vdb`) * `fstype`: The type of filesystem to create on the block device * `mountpoint`: The location in the filesystem hierarchy where the volume is mounted * `opts`: (Optional) options to pass to the `mkfs` program when formatting the device * `mountopts`: (Optional) additional options to pass to the `mount` program when mounting the filesystem --- datavol.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 datavol.yml diff --git a/datavol.yml b/datavol.yml new file mode 100644 index 0000000..e16225a --- /dev/null +++ b/datavol.yml @@ -0,0 +1,52 @@ +- hosts: all + vars: + mkfs_package: + btrfs: btrfs-progs + ext2: e2fsprogs + ext3: e2fsprogs + ext4: e2fsprogs + xfs: xfsprogs + + tasks: + - name: ensure filesystem tools are installed + package: + name: >- + {{ + data_volumes + | map(attribute='fstype') + | map('extract', mkfs_package) + | list + }} + tags: + - install + + - name: ensure data volume filesystem exists + filesystem: + dev: '{{ item.dev }}' + fstype: '{{ item.fstype }}' + opts: '{{ item.opts|d(omit) }}' + loop: '{{ data_volumes|d([]) }}' + tags: + - mkfs + + - name: ensure data volume is mounted + mount: + path: '{{ item.mountpoint }}' + src: '{{ item.dev }}' + fstype: '{{ item.fstype }}' + opts: '{{ item.mountopts|d(omit) }}' + state: mounted + loop: '{{ data_volumes|d([]) }}' + notify: + - reload systemd + - fix data volume selinux context + + handlers: + - name: reload systemd + systemd: + daemon_reload: true + + - name: fix data volume selinux context + command: + restorecon -RF {{ item.mountpoint }} + loop: '{{ data_volumes }}'