From 54bcc6db49154a5d080664757584828f27d4db11 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Thu, 3 Aug 2023 09:16:42 +0200 Subject: Add rough draft of the nfs-server playbook --- playbooks.d/nfs-server/playbook.bash | 41 +++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'playbooks.d') 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 -- cgit v1.1