From 2400bbf1af78c6bfaa38c2c95d6b7390af6ebdcf Mon Sep 17 00:00:00 2001
From: Marty Oehme <contact@martyoeh.me>
Date: Fri, 28 Feb 2025 21:40:02 +0100
Subject: [PATCH] feat(backup): Default to root user using snapper

If no primary user is defined in the playbooks, we give only the root
user access to the snapper command by default.
---
 roles/backup/defaults/main.yaml                       | 2 ++
 roles/backup/templates/snapper-configurations/home.j2 | 2 +-
 roles/backup/templates/snapper-configurations/root.j2 | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)
 create mode 100644 roles/backup/defaults/main.yaml

diff --git a/roles/backup/defaults/main.yaml b/roles/backup/defaults/main.yaml
new file mode 100644
index 0000000..85242b0
--- /dev/null
+++ b/roles/backup/defaults/main.yaml
@@ -0,0 +1,2 @@
+---
+# user_name: # required for snapper templates
diff --git a/roles/backup/templates/snapper-configurations/home.j2 b/roles/backup/templates/snapper-configurations/home.j2
index ef7bcf3..48030d0 100644
--- a/roles/backup/templates/snapper-configurations/home.j2
+++ b/roles/backup/templates/snapper-configurations/home.j2
@@ -14,7 +14,7 @@ SPACE_LIMIT="0.5"
 FREE_LIMIT="0.2"
 
 # users and groups allowed to work with config
-ALLOW_USERS="{{ user_name }}"
+ALLOW_USERS="{{ user_name | default('root') }}"
 ALLOW_GROUPS=""
 
 # sync users and groups from ALLOW_USERS and ALLOW_GROUPS to .snapshots
diff --git a/roles/backup/templates/snapper-configurations/root.j2 b/roles/backup/templates/snapper-configurations/root.j2
index 6218117..2abfce2 100644
--- a/roles/backup/templates/snapper-configurations/root.j2
+++ b/roles/backup/templates/snapper-configurations/root.j2
@@ -14,7 +14,7 @@ SPACE_LIMIT="0.5"
 FREE_LIMIT="0.2"
 
 # users and groups allowed to work with config
-ALLOW_USERS="{{ user_name }}"
+ALLOW_USERS="{{ user_name | default('root') }}"
 ALLOW_GROUPS=""
 
 # sync users and groups from ALLOW_USERS and ALLOW_GROUPS to .snapshots