noheat deployment: setup NFS server and clients

Issue-ID: INT-1601
Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
Change-Id: I8de10257f75e662e8e8809061ec818def0d3f048
diff --git a/deployment/noheat/cluster-rke/ansible/create.yml b/deployment/noheat/cluster-rke/ansible/create.yml
index fa24fb1..7304dbb 100644
--- a/deployment/noheat/cluster-rke/ansible/create.yml
+++ b/deployment/noheat/cluster-rke/ansible/create.yml
@@ -1,4 +1,9 @@
 ---
+- name: Install NFS
+  hosts: all
+  become: yes
+  roles:
+    - role: setup_nfs
 - name: Set up bastion node for ONAP Docker registry
   hosts: "control0"
   become: yes
diff --git a/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/defaults/main.yml b/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/defaults/main.yml
new file mode 100644
index 0000000..da66bfb
--- /dev/null
+++ b/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+nfs_mountpoint: "/dockerdata-nfs"
diff --git a/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/tasks/main.yml b/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/tasks/main.yml
new file mode 100644
index 0000000..398b563
--- /dev/null
+++ b/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/tasks/main.yml
@@ -0,0 +1,53 @@
+- name: Install NFS common
+  apt:
+    name: nfs-common
+    state: present
+  when: nfs_role is defined
+
+- name: Install NFS server
+  apt:
+    name: nfs-kernel-server
+    state: present
+  when: nfs_role is defined and nfs_role == "server"
+
+- name: Remove leftovers
+  file:
+    path: "{{ nfs_mountpoint }}"
+    state: absent
+  when: nfs_role is defined
+
+- name: Create dockerdata directory
+  file:
+    path: "{{ nfs_mountpoint }}"
+    state: directory
+    mode: '0777'
+    owner: nobody
+    group: nogroup
+  when: nfs_role is defined
+
+- name: Configure NFS server
+  template:
+    src: "exports.j2"
+    dest: "/etc/exports"
+    owner: root
+    group: root
+    mode: '0644'
+  when: nfs_role is defined and nfs_role == "server"
+
+- name: Restart NFS server
+  service:
+    name: nfs-kernel-server
+    state: restarted
+    enabled: yes
+  when: nfs_role is defined and nfs_role == "server"
+
+- name: Configure NFS clients
+  mount:
+    path: "{{ nfs_mountpoint }}"
+    src: "{{ hostvars[groups['nfs'][0]]['ansible_default_ipv4']['address'] }}:{{ nfs_mountpoint }}"
+    fstype: nfs
+    opts: auto,nofail,noatime,nolock,intr,tcp,actimeo=1800
+    dump: 0
+    passno: 0
+    state: mounted
+  when: nfs_role is defined and nfs_role == "client"
diff --git a/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/templates/exports.j2 b/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/templates/exports.j2
new file mode 100644
index 0000000..edadcb9
--- /dev/null
+++ b/deployment/noheat/cluster-rke/ansible/roles/setup_nfs/templates/exports.j2
@@ -0,0 +1 @@
+{{ nfs_mountpoint }} {% for host in (groups['control'] | union(groups['workers'])) %} {{ hostvars[host]['ansible_default_ipv4']['address'] }}{% endfor %}(rw,sync,no_root_squash,no_subtree_check)