summaryrefslogtreecommitdiff
path: root/playbooks.d
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2023-08-03 09:16:42 +0200
committerPatrick Spek <p.spek@tyil.nl>2023-10-24 15:39:04 +0200
commit54bcc6db49154a5d080664757584828f27d4db11 (patch)
treed48c29267e065111873d7e58ca92f896717553d0 /playbooks.d
parentc0315d5ea4879bfd4d099bcabd4b0f2c569be68d (diff)
Add rough draft of the nfs-server playbook
Diffstat (limited to 'playbooks.d')
-rw-r--r--playbooks.d/nfs-server/playbook.bash41
1 files changed, 38 insertions, 3 deletions
diff --git a/playbooks.d/nfs-server/playbook.bash b/playbooks.d/nfs-server/playbook.bash
index 91efec2..6856c72 100644
--- a/playbooks.d/nfs-server/playbook.bash
+++ b/playbooks.d/nfs-server/playbook.bash
@@ -16,13 +16,48 @@ playbook_add() {
playbook_sync() {
local buffer="$(tmpfile)"
- local hash="$(file_hash /etc/exports)"
+ local exports="/etc/exports.d/kubernetes.exports"
+ local hash="$(file_hash "$exports")"
- # TODO: Write the config file!
+ local root_options="ro,no_subtree_check"
+ local export_options="rw,no_root_squash,no_subtree_check"
+ local root_export="/mnt/exports"
+ local allowed_cidr=("10.57.0.0/16" "172.19.0.0/16")
+ local fsid
+
+ {
+ printf "%s" "$root_export"
+ for host in "${allowed_cidr[@]}"
+ do
+ printf " %s(fsid=%s,%s)" "$host" "0" "$export_options"
+ done
+ printf "\n"
+
+ for path in "$root_export"/*
+ do
+ fsid="$(config "$BASHTARD_PLAYBOOK.exports.$path.fsid" "")"
+
+ if [[ "$fsid" == "" ]]
+ then
+ warn "$BASHTARD_PLAYBOOK" "Generating fsid for $path"
+ fsid="$(uuidgen)"
+ $BASHTARD_BIN var "$BASHTARD_PLAYBOOK.exports.$path.fsid" "$fsid"
+ fi
+
+ printf "%s" "$path"
+ for host in "${allowed_cidr[@]}"
+ do
+ printf " %s(fsid=%s,%s)" "$host" "$fsid" "$export_options"
+ done
+ printf "\n"
+
+ unset fsid
+ done
+ } > "$buffer"
[[ "$(file_hash "$buffer")" == "$hash" ]] && return
- mv -- "$buffer" "/etc/exports"
+ mv -- "$buffer" "$exports"
[[ "$BASHTARD_ACTION" == "add" ]] && return