From 46a18edc87737d1f05de93849d8a2a13ebb22aca Mon Sep 17 00:00:00 2001
From: Chris Hines <chris.hines@monash.edu>
Date: Fri, 20 Mar 2015 01:36:33 +0000
Subject: [PATCH] separate the exportList used on the server from the mount
 list used on the clients

---
 roles/nfs-client/tasks/mountFileSystem.yml | 14 ++++++++------
 roles/syncExports/tasks/addExports.yml     |  8 --------
 roles/syncExports/templates/exports.j2     |  9 +++------
 3 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/roles/nfs-client/tasks/mountFileSystem.yml b/roles/nfs-client/tasks/mountFileSystem.yml
index 555e12b5..0dc48290 100644
--- a/roles/nfs-client/tasks/mountFileSystem.yml
+++ b/roles/nfs-client/tasks/mountFileSystem.yml
@@ -4,16 +4,18 @@
   sudo: true
 
 
+
+
 - name: "Mounting NFS mounts"
-  mount: name={{ item.name }} src={{ item.ipv4 }}:{{ item.src }} fstype={{ item.fstype }} opts={{ item.opts }} state=mounted
-  with_items: exportList 
+  mount: name={{ item.mntpt }} src={{ item.src }} fstype={{ item.fstype }} opts={{ item.opts }} state=mounted
+  with_items: nfsMounts
   notify: "restart authentication"
   notify: "restart rpcbind"
   notify: "restart idmap"
   sudo: true 
   ignore_errors: true
   register: firstMount
-  when: exportList is defined 
+  when: nfsMounts is defined 
 
 - name: "Wait for nfs to stabailse"
   command: sleep 60
@@ -21,13 +23,13 @@
   when: firstMount | failed
 
 - name: "Mounting NFS mounts"
-  mount: name={{ item.name }} src={{ item.ipv4 }}:{{ item.src }} fstype={{ item.fstype }} opts={{ item.opts }} state=mounted
-  with_items: exportList 
+  mount: name={{ item.name }} src=" {{ item.ipv4 }}:{{ item.src }} " fstype={{ item.fstype }} opts={{ item.opts }} state=mounted
+  with_items: nfsMounts
   notify: "restart authentication"
   notify: "restart idmap"
   notify: "restart rpcbind"
   sudo: true 
-  when: exportList is defined and firstMount | failed
+  when: nfsMounts is defined and firstMount | failed
 
 - name: "restart fail2ban"
   service: name=fail2ban state=started
diff --git a/roles/syncExports/tasks/addExports.yml b/roles/syncExports/tasks/addExports.yml
index f91dd861..8853541b 100644
--- a/roles/syncExports/tasks/addExports.yml
+++ b/roles/syncExports/tasks/addExports.yml
@@ -2,26 +2,18 @@
 - name: "Create exports if necessary"
   file: dest={{ item.src }} state=directory mode=755 owner=root group=root
   sudo: true
-  delegate_to: "{{ nfs_server }}"
-  run_once: true
   with_items: exportList
 
 - name: "Templating /etc/exports"
   template: src=exports.j2 dest=/etc/exports owner=root group=root mode=644
-  delegate_to: "{{ nfs_server }}"
-  run_once: true
   sudo: true
 
 # Do not do this as a handler, instead do this here as a task so that it happens imediatly after the exports file is created before any clients
 # attempt a mount
 - name : "Reload exports"
   command: exportfs -ra
-  delegate_to: "{{ nfs_server }}"
-  run_once: true
   sudo: true
 
 - name : "Pause ... clients sometimes have errors"
   command: sleep 60
-  delegate_to: "{{ nfs_server }}"
-  run_once: true
   sudo: true
diff --git a/roles/syncExports/templates/exports.j2 b/roles/syncExports/templates/exports.j2
index 21c4f552..b480290d 100644
--- a/roles/syncExports/templates/exports.j2
+++ b/roles/syncExports/templates/exports.j2
@@ -1,13 +1,10 @@
 {% set iplist = [] %}
 {% for export in exportList %}
-{% for group in groupList %}
-{% for node in groups[group.name] %}
-{% if hostvars[node]['ansible_'+group.interface] is defined %}
-{% if iplist.append(hostvars[node]['ansible_'+group.interface]['ipv4']['address']) %}
+{% for node in groups[export.group] %}
+{% if hostvars[node]['ansible_'+export.interface] is defined %}
+{% if iplist.append(hostvars[node]['ansible_'+export.interface]['ipv4']['address']) %} 
 {% endif %}
 {% endif %}
 {% endfor %}
-{% endfor %}
 {{ export.src }} {% for ip in iplist|unique %}{{ ip }}({{ export.srvopts }}) {% endfor %}
-
 {% endfor %}
-- 
GitLab