summaryrefslogtreecommitdiffstats
path: root/roles/mount
diff options
context:
space:
mode:
Diffstat (limited to 'roles/mount')
-rw-r--r--roles/mount/README.md75
-rw-r--r--roles/mount/defaults/main.yml4
-rw-r--r--roles/mount/meta/argument_specs.yml20
-rw-r--r--roles/mount/meta/main.yml11
-rw-r--r--roles/mount/tasks/main.yml18
5 files changed, 128 insertions, 0 deletions
diff --git a/roles/mount/README.md b/roles/mount/README.md
new file mode 100644
index 00000000..c82c777a
--- /dev/null
+++ b/roles/mount/README.md
@@ -0,0 +1,75 @@
+# Mount Role
+
+Mounts a drive on the target host.
+
+## Overview
+
+Prepares a storage device as a mount point (e.g. local backup destination for S3-compatible object store like Garage).
+
+## Configuration
+
+### Required Variables
+
+```yaml
+mount_device: "PARTLABEL=backup" # no default — must set in host_vars
+```
+
+### Optional Variables
+
+```yaml
+mount_point: "/backup"
+mount_fstype: "ext4"
+mount_options: "defaults,noatime"
+```
+
+## Preparing the Drive
+
+### 1. Install parted
+
+```bash
+sudo apt install parted
+```
+
+### 2. Partition with a named label
+
+```bash
+# check device name
+lsblk
+
+# create GPT partition table + single labeled partition
+sudo parted /dev/sdX --script mklabel gpt mkpart backup ext4 0% 100%
+sudo parted /dev/nvme0nX --script mklabel gpt mkpart backup ext4 0% 100%
+
+# verify label
+sudo parted /dev/sdX print
+sudo parted /dev/nvme0nX print
+```
+
+### 3. Format as ext4
+
+```bash
+sudo mkfs.ext4 /dev/sdX1
+sudo mkfs.ext4 /dev/nvme0nXp1
+
+# verify
+sudo blkid /dev/sdX1
+sudo blkid /dev/nvme0nXp1
+
+ls /dev/disk/by-partlabel/
+```
+
+### 4. Set host variable
+
+In `host_vars/rpi5.local.yml`:
+
+```yaml
+mount_device: "PARTLABEL=backup"
+```
+
+`PARTLABEL` is stable across reboots regardless of device enumeration order (`/dev/sda` vs `/dev/sdb`).
+`ansible.posix.mount` handles `PARTLABEL=` values natively.
+
+## Notes
+
+- `noatime` mount option reduces unnecessary write cycles on the drive
+- Role adds a persistent fstab entry — drive auto-mounts on reboot
diff --git a/roles/mount/defaults/main.yml b/roles/mount/defaults/main.yml
new file mode 100644
index 00000000..325e0e51
--- /dev/null
+++ b/roles/mount/defaults/main.yml
@@ -0,0 +1,4 @@
+---
+mount_point: "/backup"
+mount_fstype: "ext4"
+mount_options: "defaults,noatime"
diff --git a/roles/mount/meta/argument_specs.yml b/roles/mount/meta/argument_specs.yml
new file mode 100644
index 00000000..e74c1610
--- /dev/null
+++ b/roles/mount/meta/argument_specs.yml
@@ -0,0 +1,20 @@
+---
+argument_specs:
+ main:
+ options:
+ mount_device:
+ type: "str"
+ description: "Device to mount (e.g. PARTLABEL=backup)"
+ required: true
+ mount_point:
+ type: "str"
+ description: "Mount point for the drive"
+ default: "/mnt/backup"
+ mount_fstype:
+ type: "str"
+ description: "Filesystem type of the device"
+ default: "ext4"
+ mount_options:
+ type: "str"
+ description: "Mount options for the device"
+ default: "defaults,noatime"
diff --git a/roles/mount/meta/main.yml b/roles/mount/meta/main.yml
new file mode 100644
index 00000000..ccb8c2a9
--- /dev/null
+++ b/roles/mount/meta/main.yml
@@ -0,0 +1,11 @@
+---
+dependencies: []
+galaxy_info:
+ author: "a14m"
+ description: "Mount a drive"
+ license: "MIT"
+ min_ansible_version: "2.18"
+ platforms:
+ - name: "Debian"
+ versions:
+ - "bookworm"
diff --git a/roles/mount/tasks/main.yml b/roles/mount/tasks/main.yml
new file mode 100644
index 00000000..65e40416
--- /dev/null
+++ b/roles/mount/tasks/main.yml
@@ -0,0 +1,18 @@
+---
+- name: "Create mount point"
+ become: true
+ ansible.builtin.file:
+ path: "{{ mount_point }}"
+ state: "directory"
+ owner: "root"
+ group: "root"
+ mode: "0755"
+
+- name: "Mount drive"
+ become: true
+ ansible.posix.mount:
+ path: "{{ mount_point }}"
+ src: "{{ mount_device }}"
+ fstype: "{{ mount_fstype }}"
+ opts: "{{ mount_options }}"
+ state: "mounted"