aboutsummaryrefslogtreecommitdiffstats
path: root/roles/nfsclient/tasks
diff options
context:
space:
mode:
authorbinary <me@rgoncalves.se>2021-03-03 14:57:10 +0100
committerbinary <me@rgoncalves.se>2021-03-03 14:57:10 +0100
commitdde73d89a725ad764509aa623c945cfa789ae2e4 (patch)
treebfcdc3325c3edabd9ee51caeab430974f2ce2b15 /roles/nfsclient/tasks
parent3147612e821c234c8df7a82760b66a6c373f799a (diff)
downloadinfrastructure-dde73d89a725ad764509aa623c945cfa789ae2e4.tar.gz
Add nfsclient role for mounting data in VM from hypervisor
Diffstat (limited to 'roles/nfsclient/tasks')
-rw-r--r--roles/nfsclient/tasks/_alpine.yml16
-rw-r--r--roles/nfsclient/tasks/_openbsd.yml0
-rw-r--r--roles/nfsclient/tasks/main.yml66
3 files changed, 82 insertions, 0 deletions
diff --git a/roles/nfsclient/tasks/_alpine.yml b/roles/nfsclient/tasks/_alpine.yml
new file mode 100644
index 0000000..86e21d9
--- /dev/null
+++ b/roles/nfsclient/tasks/_alpine.yml
@@ -0,0 +1,16 @@
+
+# nfsclient ~~ roles/nfsclient/tasks/_alpine.yml
+# alpine prerequisites
+
+---
+
+- name: install nfs-utils
+ package:
+ name: nfs-utils
+ state: present
+
+- name: ensure that nfsmount is restarted and enabled
+ service:
+ name: nfsmount
+ state: restarted
+ enabled: true
diff --git a/roles/nfsclient/tasks/_openbsd.yml b/roles/nfsclient/tasks/_openbsd.yml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/roles/nfsclient/tasks/_openbsd.yml
diff --git a/roles/nfsclient/tasks/main.yml b/roles/nfsclient/tasks/main.yml
new file mode 100644
index 0000000..f84c926
--- /dev/null
+++ b/roles/nfsclient/tasks/main.yml
@@ -0,0 +1,66 @@
+
+# nfsclient ~~ roles/nfsclient/tasks/main.yml
+# setup nfs client for a given server
+
+---
+
+- name: fallback to default nfs server
+ set_fact:
+ nfsclient_server: "{{ global.nfs_server }}"
+ when: nfsclient_server is not defined
+
+- name: fallback default nfs server directory
+ set_fact:
+ nfsclient_server_dir: "{{ global.nfs_server_dir }}"
+ when: nfsclient_server_dir is not defined
+
+- name: translate server string to server dict if not
+ set_fact:
+ nfsclient_server: "{{ hostvars[nfsclient_server] }}"
+
+- name: include distribution specific prerequisites
+ include_tasks: "_{{ ansible_distribution | lower }}.yml"
+ ignore_errors: true
+
+- name: ensure tmp directory exists for testing nfsd
+ file:
+ path: "{{ nfsclient_test_dir }}"
+ owner: 0
+ group: 0
+ mode: 0700
+ state: directory
+
+- name: test nfs setup
+ shell: mount -t nfs "{{ nfsclient_server.ip.out }}:{{ nfsclient_server_dir }}" /tmp/nfsd-test
+
+- name: cleanup fstab with previous nfs setup
+ lineinfile:
+ path: /etc/fstab
+ regexp: ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:/.* {{ nfsclient_dir }} nfs
+ state: absent
+
+- name: complete fstab with nfs
+ lineinfile:
+ path: /etc/fstab
+ line: "{{ nfsclient_server.ip.out }}:{{ nfsclient_server_dir }} {{ nfsclient_dir }} nfs rw,nodev,nosuid 0 0"
+
+- name: reload fstab
+ shell: |
+ umount -af -t nfs
+ mount -a
+ ignore_errors: true
+
+- name: remove nfs test directory
+ file:
+ path: "{{ nfsclient_test_dir }}"
+ state: absent
+
+- name: register mounted volumes
+ shell: df -P | grep nfs
+ register: out
+
+- name: display mounted volumes
+ debug:
+ msg: |
+ {{ out.stdout_lines }}
+ {{ out.stderr_lines }}
remember that computers suck.