]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add find_host function to help finding host
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 25 Jun 2018 22:27:26 +0000 (00:27 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 25 Jun 2018 22:50:56 +0000 (00:50 +0200)
modules/profile/manifests/postgresql_master.pp

index 3f68890d4edc00790122b09108555c70454f9ec3..9966f0d041020fce760e39cacaf6e41e28a97505 100644 (file)
@@ -52,36 +52,35 @@ define profile::postgresql_master (
   $backup_hosts.each |$backup_host| {
     ensure_packages(["pam_ldap"])
 
-    $facts["ldapvar"]["other"].each |$host| {
-      if ($host["cn"][0] == $backup_host) {
-        $host["ipHostNumber"].each |$ip| {
-          $infos = split($ip, "/")
-          $ipaddress = $infos[0]
-          if (length($infos) == 1 and $ipaddress =~ /:/) {
-            $mask = "128"
-          } elsif (length($infos) == 1) {
-            $mask = "32"
-          } else {
-            $mask = $infos[1]
-          }
-
-          postgresql::server::pg_hba_rule { "allow TCP access to replication user from backup for replication from $ipaddress/$mask":
-            type        => 'hostssl',
-            database    => 'replication',
-            user        => $backup_host,
-            address     => "$ipaddress/$mask",
-            auth_method => 'pam',
-            order       => "06-01",
-          }
+    $host = find_host($facts["ldapvar"]["other"], $backup_host)
+    unless empty($host) {
+      $host["ipHostNumber"].each |$ip| {
+        $infos = split($ip, "/")
+        $ipaddress = $infos[0]
+        if (length($infos) == 1 and $ipaddress =~ /:/) {
+          $mask = "128"
+        } elsif (length($infos) == 1) {
+          $mask = "32"
+        } else {
+          $mask = $infos[1]
         }
 
-        postgresql::server::role { $backup_host:
-          replication => true,
+        postgresql::server::pg_hba_rule { "allow TCP access to replication user from backup for replication from $ipaddress/$mask":
+          type        => 'hostssl',
+          database    => 'replication',
+          user        => $backup_host,
+          address     => "$ipaddress/$mask",
+          auth_method => 'pam',
+          order       => "06-01",
         }
+      }
 
-        postgresql_replication_slot { regsubst($backup_host, '-', "_", "G"):
-          ensure => present
-        }
+      postgresql::server::role { $backup_host:
+        replication => true,
+      }
+
+      postgresql_replication_slot { regsubst($backup_host, '-', "_", "G"):
+        ensure => present
       }
     }