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
frigate-exporter
Dustin 2024-06-29 07:27:59 -05:00
parent edffaf258b
commit 54ad68b5bb
1 changed files with 52 additions and 0 deletions

52
datavol.yml Normal file
View File

@ -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 }}'