Add ansible nfs role 86/74886/1
authorMichal Zegan <m.zegan@samsung.com>
Wed, 19 Dec 2018 10:47:30 +0000 (11:47 +0100)
committerMichal Zegan <m.zegan@samsung.com>
Wed, 19 Dec 2018 10:47:30 +0000 (11:47 +0100)
This commit adds role for creating /dockerdata-nfs
and exporting i over nfs for later use during onap deployment.

Change-Id: I0ea8e858d581534b983eaab6e1ee570068fc623c
Issue-ID: OOM-1551
Signed-off-by: Michal Zegan <m.zegan@samsung.com>
ansible/roles/nfs/defaults/main.yml [new file with mode: 0644]
ansible/roles/nfs/tasks/main.yml [new file with mode: 0644]
ansible/roles/nfs/templates/exports.j2 [new file with mode: 0644]

diff --git a/ansible/roles/nfs/defaults/main.yml b/ansible/roles/nfs/defaults/main.yml
new file mode 100644 (file)
index 0000000..a5e1d2a
--- /dev/null
@@ -0,0 +1,5 @@
+---
+nfs_services:
+  RedHat:
+    - rpcbind
+    - nfs
diff --git a/ansible/roles/nfs/tasks/main.yml b/ansible/roles/nfs/tasks/main.yml
new file mode 100644 (file)
index 0000000..32194d1
--- /dev/null
@@ -0,0 +1,33 @@
+---
+- name: Create nfs directory
+  file:
+    path: "{{ nfs_mount_path }}"
+    state: directory
+    mode: 0777
+
+- name: Setup nfs server
+  block:
+    - name: Start services
+      systemd:
+        name: "{{ item }}"
+        state: started
+      with_items: "{{ nfs_services[ansible_os_family] }}"
+
+    - name: Add hosts to exports
+      template:
+        src: exports.j2
+        dest: /etc/exports
+
+    - name: Export nfs
+      command: exportfs -ar
+  when:
+    - "'nfs-server' in group_names"
+
+- name: Mount dockerdata-nfs
+  mount:
+    path: "{{ nfs_mount_path }}"
+    src: "{{ hostvars[groups['nfs-server'].0].ansible_host }}:{{ nfs_mount_path }}"
+    fstype: nfs
+    state: mounted
+  when:
+    - "'nfs-server' not in group_names"
diff --git a/ansible/roles/nfs/templates/exports.j2 b/ansible/roles/nfs/templates/exports.j2
new file mode 100644 (file)
index 0000000..1f6956c
--- /dev/null
@@ -0,0 +1,3 @@
+{% for host in groups.kubernetes[1:] -%}
+    {{ nfs_mount_path }}  {{ hostvars[host].ansible_host }}(rw,sync,no_root_squash,no_subtree_check)
+{% endfor %}