aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--roles/nfs/README.md2
-rw-r--r--roles/nfs/defaults/main.yml5
-rw-r--r--roles/nfs/handlers/main.yml4
-rw-r--r--roles/nfs/tasks/main.yml26
-rw-r--r--roles/nfs/templates/exports.j211
5 files changed, 48 insertions, 0 deletions
diff --git a/roles/nfs/README.md b/roles/nfs/README.md
new file mode 100644
index 0000000..b26e8e7
--- /dev/null
+++ b/roles/nfs/README.md
@@ -0,0 +1,2 @@
+This role installs the NFS server & configures a mount. It doesn't support
+multiple mounts or anything like that.
diff --git a/roles/nfs/defaults/main.yml b/roles/nfs/defaults/main.yml
new file mode 100644
index 0000000..0308c64
--- /dev/null
+++ b/roles/nfs/defaults/main.yml
@@ -0,0 +1,5 @@
+#nfs_dir:
+nfs_opts:
+nfs_all_squash: false
+#nfs_anonuid:
+#nfs_anongid:
diff --git a/roles/nfs/handlers/main.yml b/roles/nfs/handlers/main.yml
new file mode 100644
index 0000000..e92820d
--- /dev/null
+++ b/roles/nfs/handlers/main.yml
@@ -0,0 +1,4 @@
+- name: Reload NFS mounts
+ become: true
+ ansible.builtin.command: /usr/sbin/exportfs -arv
+ listen: nfs_configured
diff --git a/roles/nfs/tasks/main.yml b/roles/nfs/tasks/main.yml
new file mode 100644
index 0000000..f8045e3
--- /dev/null
+++ b/roles/nfs/tasks/main.yml
@@ -0,0 +1,26 @@
+- name: Install NFS
+ become: true
+ ansible.builtin.package:
+ name: nfs-server
+ state: present
+
+- name: Enable & start NFS service
+ become: true
+ ansible.builtin.systemd_service:
+ name: nfs-server
+ enabled: true
+ state: started
+
+- name: Collect required info
+ ansible.builtin.setup:
+ gather_subset: [user]
+
+- name: Configure NFS
+ become: true
+ ansible.builtin.template:
+ src: exports.j2
+ dest: /etc/exports
+ owner: root
+ group: root
+ mode: '644'
+ notify: nfs_configured
diff --git a/roles/nfs/templates/exports.j2 b/roles/nfs/templates/exports.j2
new file mode 100644
index 0000000..301bb45
--- /dev/null
+++ b/roles/nfs/templates/exports.j2
@@ -0,0 +1,11 @@
+{% set _opts = 'rw,sync,insecure,no_subtree_check' %}
+{% if nfs_opts %}
+ {% set _opts %}{{ _opts }},{{ nfs_opts }}{% endset %}
+{% endif %}
+{% if nfs_all_squash %}
+ {% set _anonuid = nfs_anonuid if nfs_anonuid is defined else ansible_facts['user_uid'] %}
+ {% set _anongid = nfs_anongid if nfs_anongid is defined else ansible_facts['user_gid'] %}
+ {% set _opts %}{{ _opts }},all_squash,anonuid={{ _anonuid }},anongid={{ _anongid }}{% endset %}
+{% endif %}
+
+{{ nfs_dir }} *({{ _opts }})