Fix nfs role issues based on molecule testing 01/83101/3
authorSamuli Silvius <s.silvius@partner.samsung.com>
Sat, 23 Mar 2019 11:54:34 +0000 (13:54 +0200)
committerSamuli Silvius <s.silvius@partner.samsung.com>
Mon, 1 Apr 2019 17:41:43 +0000 (20:41 +0300)
Based on Molecule testing fix following issues on
nfs role.

 - enable nfs services (previously only started)
 - create handler for exportfs to deal idempotency
 - add all kubernetes nodes to exports as it was dependent on ansible inventory order wheather correct hosts was on the list
 - add inventory_hostname as default host incase ansible_host variable not defined.

Issue-ID: OOM-1756

Change-Id: Ib93e9d2a9cf49003d04dd5f890294eda1eb966ff
Signed-off-by: Samuli Silvius <s.silvius@partner.samsung.com>
ansible/roles/nfs/handlers/main.yml [new file with mode: 0644]
ansible/roles/nfs/tasks/main.yml
ansible/roles/nfs/templates/exports.j2

diff --git a/ansible/roles/nfs/handlers/main.yml b/ansible/roles/nfs/handlers/main.yml
new file mode 100644 (file)
index 0000000..4b8deae
--- /dev/null
@@ -0,0 +1,3 @@
+---
+- name: reload nfs
+  command: exportfs -ra
index aca1771..e7580b6 100644 (file)
@@ -9,7 +9,7 @@
   package:
     name: "{{ item }}"
     state: present
-  with_items: "{{ nfs_packages[ansible_os_family] }}"
+  loop: "{{ nfs_packages[ansible_os_family] }}"
 
 - name: Setup nfs server
   block:
       systemd:
         name: "{{ item }}"
         state: started
-      with_items: "{{ nfs_services[ansible_os_family] }}"
+        enabled: true
+      loop: "{{ nfs_services[ansible_os_family] }}"
 
     - name: Add hosts to exports
       template:
         src: exports.j2
         dest: /etc/exports
-
-    - name: Export nfs
-      command: exportfs -ar
+      notify:
+        - reload nfs
   when:
     - "'nfs-server' in group_names"
 
+- name: Force notified handlers to run at this point
+  meta: flush_handlers
+
 - name: Mount dockerdata-nfs
   mount:
     path: "{{ nfs_mount_path }}"
-    src: "{{ hostvars[groups['nfs-server'].0].ansible_host }}:{{ nfs_mount_path }}"
+    src: "{{ hostvars[groups['nfs-server'].0].ansible_host | default(hostvars[groups['nfs-server'].0].inventory_hostname) }}:{{ nfs_mount_path }}"
     fstype: nfs
     state: mounted
   when:
index 1f6956c..c605d9b 100644 (file)
@@ -1,3 +1,3 @@
-{% for host in groups.kubernetes[1:] -%}
-    {{ nfs_mount_path }}  {{ hostvars[host].ansible_host }}(rw,sync,no_root_squash,no_subtree_check)
+{% for host in groups.kubernetes -%}
+    {{ nfs_mount_path }}  {{ hostvars[host].ansible_host | default(hostvars[host].inventory_hostname) }}(rw,sync,no_root_squash,no_subtree_check)
 {% endfor %}