]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Cleanup backup hosts information lookup
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 25 Jun 2018 22:39:14 +0000 (00:39 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 25 Jun 2018 22:44:53 +0000 (00:44 +0200)
modules/base_installation/lib/puppet/parser/functions/find_host.rb [new file with mode: 0644]
modules/role/manifests/backup/postgresql.pp

diff --git a/modules/base_installation/lib/puppet/parser/functions/find_host.rb b/modules/base_installation/lib/puppet/parser/functions/find_host.rb
new file mode 100644 (file)
index 0000000..79aae5c
--- /dev/null
@@ -0,0 +1,18 @@
+module Puppet::Parser::Functions
+  newfunction(:find_host, :type => :rvalue, :doc => <<-EOS
+This function searches through the hosts to find the one with matching cn
+    EOS
+  ) do |arguments|
+
+    if (arguments.size != 2) then
+      raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2")
+    end
+
+    hosts = arguments[0]
+    cn = arguments[1]
+
+    hosts.find { |host| host["cn"].any? { |cn_| cn_ == cn } }
+  end
+end
+
+# vim: set ts=2 sw=2 et :
index e891195c83a72d977f49e5bf0707868c1a281960..b26773c39ed51e69980c1c0bb0ba48bedf48f8d3 100644 (file)
@@ -94,7 +94,15 @@ class role::backup::postgresql inherits role::backup {
     }
   }
 
-  $pg_backup_hosts.each |$pg_backup_host, $pg_infos| {
+  $pg_backup_hosts.each |$backup_host_cn, $pg_infos| {
+    $host = find_host($facts["ldapvar"]["other"], $backup_host_cn)
+    if empty($host) {
+      $pg_backup_host = $backup_host_cn
+    } elsif has_key($host["vars"], "host") {
+      $pg_backup_host = $host["vars"]["host"][0]
+    } else {
+      $pg_backup_host = $host["vars"]["real_hostname"][0]
+    }
     $pg_path = "$mountpoint/$pg_backup_host/postgresql"
     $pg_backup_path = "$mountpoint/$pg_backup_host/postgresql_backup"
     $pg_host = "$pg_backup_host"