]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Group hosts in single export line file_store
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 18 Aug 2018 17:45:20 +0000 (19:45 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 11 Nov 2018 10:02:43 +0000 (11:02 +0100)
modules/role/manifests/file_store.pp
modules/role/templates/file_store/nfs_clients.erb [new file with mode: 0644]

index d1f6a6794a6ccd2ea3448bcf30bd695909b52600..665a32bc9fd6ae0a3c7069bd51128ff3e1cfc674 100644 (file)
@@ -26,36 +26,12 @@ class role::file_store (
         group   => "nobody",
         require => Mount[$mountpoint],
       }
-
-      $hosts.each |$host_cn| {
-        $host = find_host($facts["ldapvar"]["other"], $host_cn)
-        if empty($host) {
-          fail("No host found for nfs")
-        } elsif has_key($host["vars"], "wireguard_ip") {
-          $clients = sprintf("%s%s",
-            join($host["vars"]["wireguard_ip"], "(rw,secure,sync,all_squash) "),
-            "(rw,secure,sync,all_squash)")
-          nfs::server::export { "$mountpoint/$nfs_mount":
-            owner   => "nobody",
-            group   => "nobody",
-            ensure  => "present",
-            clients => $clients,
-          }
-        } elsif has_key($host["vars"], "host") {
-          nfs::server::export { "$mountpoint/$nfs_mount":
-            owner   => "nobody",
-            group   => "nobody",
-            ensure  => "present",
-            clients => "${host[vars][host][0]}(rw,secure,sync,all_squash)",
-          }
-        } else {
-          nfs::server::export { "$mountpoint/$nfs_mount":
-            owner   => "nobody",
-            group   => "nobody",
-            ensure  => "present",
-            clients => "${host[vars][real_hostname][0]}(rw,secure,sync,all_squash)",
-          }
-        }
+      ->
+      nfs::server::export { "$mountpoint/$nfs_mount":
+        owner   => "nobody",
+        group   => "nobody",
+        ensure  => "present",
+        clients => template("role/file_store/nfs_clients.erb"),
       }
     }
   }
diff --git a/modules/role/templates/file_store/nfs_clients.erb b/modules/role/templates/file_store/nfs_clients.erb
new file mode 100644 (file)
index 0000000..0d8a295
--- /dev/null
@@ -0,0 +1,12 @@
+<%= @hosts.flat_map do |host_cn, config|
+  host = scope.function_find_host([@facts["ldapvar"]["other"], host_cn])
+  if host.nil?
+    [host_cn]
+  elsif !host["vars"]["wireguard_ip"].nil?
+    host["vars"]["wireguard_ip"]
+  elsif !host["vars"]["host"].nil?
+    host["vars"]["host"]
+  else
+    host["vars"]["real_hostname"]
+  end.map { |h| h + config }
+end.join(" ") -%>