From 3bdd93b16d98af2f725ce23e40f0ca53f27a73a0 Mon Sep 17 00:00:00 2001
From: David Kilias <david.kilias@gmail.com>
Date: Mon, 9 Oct 2023 18:45:38 +0200
Subject: [PATCH] feat: make nfs exports more configurable

---
 roles/nfs-host/defaults/main.yml    | 6 +++++-
 roles/nfs-host/tasks/main.yml       | 7 +++----
 roles/nfs-host/templates/exports.j2 | 4 +++-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/roles/nfs-host/defaults/main.yml b/roles/nfs-host/defaults/main.yml
index 634be53..386ccf7 100644
--- a/roles/nfs-host/defaults/main.yml
+++ b/roles/nfs-host/defaults/main.yml
@@ -1,4 +1,8 @@
 # Defaults for nfs-host
 ---
-nfs_host_mount_point: "/srv/nfs"
+nfs_host_exports:
+  - directory: "/srv/nfs"
+    hosts: "k3s-w[0-9]+.n39.eu"
+    options: rw,sync,no_subtree_check
+
 nfs_host_storage_device: "/dev/sdb"
\ No newline at end of file
diff --git a/roles/nfs-host/tasks/main.yml b/roles/nfs-host/tasks/main.yml
index f98c2bb..ceb1644 100644
--- a/roles/nfs-host/tasks/main.yml
+++ b/roles/nfs-host/tasks/main.yml
@@ -14,15 +14,14 @@
 
 - name: ensure nfs mountpoint is present
   ansible.builtin.file:
-    path: "{{ nfs_host_mount_point }}"
+    path: "{{ item.directory }}"
     state: directory
     owner: nobody
     group: nogroup
     mode: '0000'
+  loop: "{{ nfs_host_exports | dict2items }}"
 
-# modify /etc/exports#
-# echo '/srv/nfs 10.0.0.0/24(rw,sync,no_subtree_check)'
-- name: ensure exports file has k3s ips
+- name: template /etc/exports
   ansible.builtin.template:
     src: templates/exports.j2
     dest: "/etc/exports"
diff --git a/roles/nfs-host/templates/exports.j2 b/roles/nfs-host/templates/exports.j2
index 847b8de..87d2c20 100644
--- a/roles/nfs-host/templates/exports.j2
+++ b/roles/nfs-host/templates/exports.j2
@@ -1 +1,3 @@
-{{ nfs_host_mount_point }} k3s-w[0-9]+.n39.eu(rw,sync,no_subtree_check)
\ No newline at end of file
+{% for export in nfs_host_exports %}
+{{ export.directory }} {{ export.hosts }}({{ export.options }})
+{% endfor %}
\ No newline at end of file