]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Allow host to replicate the cluster from backup
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 25 Jun 2018 23:04:09 +0000 (01:04 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 27 Jun 2018 07:07:50 +0000 (09:07 +0200)
modules/profile/manifests/postgresql_master.pp
modules/role/manifests/backup/postgresql.pp
modules/role/templates/backup/pam_ldap_pgbouncer.conf.erb
python/reboot_ovh_cloud_instance.py

index 9966f0d041020fce760e39cacaf6e41e28a97505..6f8854d7e1eb091a9753102f050f2c01e882b95e 100644 (file)
@@ -83,33 +83,33 @@ define profile::postgresql_master (
         ensure => present
       }
     }
+  }
 
-    $ldap_server = lookup("base_installation::ldap_server")
-    $ldap_base   = lookup("base_installation::ldap_base")
-    $ldap_dn     = lookup("base_installation::ldap_dn")
-    $ldap_password = generate_password(24, $password_seed, "ldap")
-    $ldap_attribute = "cn"
+  $ldap_server = lookup("base_installation::ldap_server")
+  $ldap_base   = lookup("base_installation::ldap_base")
+  $ldap_dn     = lookup("base_installation::ldap_dn")
+  $ldap_password = generate_password(24, $password_seed, "ldap")
+  $ldap_attribute = "cn"
 
-    file { "/etc/pam_ldap.d":
-      ensure => directory,
-      mode   => "0755",
-      owner  => "root",
-      group  => "root",
-    } ->
-    file { "/etc/pam_ldap.d/postgresql.conf":
-      ensure  => "present",
-      mode    => "0600",
-      owner   => $::profile::postgresql::pg_user,
-      group   => "root",
-      content => template("profile/postgresql_master/pam_ldap_postgresql.conf.erb"),
-    } ->
-    file { "/etc/pam.d/postgresql":
-      ensure => "present",
-      mode   => "0644",
-      owner  => "root",
-      group  => "root",
-      source => "puppet:///modules/profile/postgresql_master/pam_postgresql"
-    }
+  file { "/etc/pam_ldap.d":
+    ensure => directory,
+    mode   => "0755",
+    owner  => "root",
+    group  => "root",
+  } ->
+  file { "/etc/pam_ldap.d/postgresql.conf":
+    ensure  => "present",
+    mode    => "0600",
+    owner   => $::profile::postgresql::pg_user,
+    group   => "root",
+    content => template("profile/postgresql_master/pam_ldap_postgresql.conf.erb"),
+  } ->
+  file { "/etc/pam.d/postgresql":
+    ensure => "present",
+    mode   => "0644",
+    owner  => "root",
+    group  => "root",
+    source => "puppet:///modules/profile/postgresql_master/pam_postgresql"
   }
 
 }
index b26773c39ed51e69980c1c0bb0ba48bedf48f8d3..9e1c9f706d1c66521d640fe8850b71ff8b938b24 100644 (file)
@@ -13,7 +13,7 @@ class role::backup::postgresql inherits role::backup {
   $ldap_server = lookup("base_installation::ldap_server")
   $ldap_base   = lookup("base_installation::ldap_base")
   $ldap_dn     = lookup("base_installation::ldap_dn")
-  $ldap_attribute = "uid"
+  $pgbouncer_ldap_attribute = "uid"
 
   $pg_slot = regsubst($ldap_cn, '-', "_", "G")
 
@@ -71,18 +71,13 @@ class role::backup::postgresql inherits role::backup {
         ],
       }
 
-      file { "/etc/pam_ldap.d":
-        ensure => directory,
-        mode   => "0755",
-        owner  => "root",
-        group  => "root",
-      } ->
       file { "/etc/pam_ldap.d/pgbouncer.conf":
         ensure  => "present",
         mode    => "0600",
         owner   => $pg_user,
         group   => "root",
         content => template("role/backup/pam_ldap_pgbouncer.conf.erb"),
+        require => File["/etc/pam_ldap.d"],
       } ->
       file { "/etc/pam.d/pgbouncer":
         ensure => "present",
@@ -94,6 +89,29 @@ class role::backup::postgresql inherits role::backup {
     }
   }
 
+  $ldap_attribute = "cn"
+
+  file { "/etc/pam_ldap.d":
+    ensure => directory,
+    mode   => "0755",
+    owner  => "root",
+    group  => "root",
+  } ->
+  file { "/etc/pam_ldap.d/postgresql.conf":
+    ensure  => "present",
+    mode    => "0600",
+    owner   => $pg_user,
+    group   => "root",
+    content => template("profile/postgresql_master/pam_ldap_postgresql.conf.erb"),
+  } ->
+  file { "/etc/pam.d/postgresql":
+    ensure => "present",
+    mode   => "0644",
+    owner  => "root",
+    group  => "root",
+    source => "puppet:///modules/profile/postgresql_master/pam_postgresql"
+  }
+
   $pg_backup_hosts.each |$backup_host_cn, $pg_infos| {
     $host = find_host($facts["ldapvar"]["other"], $backup_host_cn)
     if empty($host) {
@@ -108,6 +126,31 @@ class role::backup::postgresql inherits role::backup {
     $pg_host = "$pg_backup_host"
     $pg_port = $pg_infos["dbport"]
 
+    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::pg_hba_rule { "allow TCP access for initial replication from $ipaddress/$mask":
+          type        => 'hostssl',
+          database    => 'replication',
+          user        => $backup_host_cn,
+          address     => "$ipaddress/$mask",
+          auth_method => 'pam',
+          order       => "06-01",
+          target      => "$pg_path/pg_hba.conf",
+          postgresql_version => "10",
+        }
+      }
+    }
+
     if !empty($ldap_filter) and ($pg_infos["pgbouncer"]) {
       concat::fragment { "pgbouncer_$pg_backup_host":
         target  => "/etc/pgbouncer/pgbouncer.ini",
@@ -292,6 +335,11 @@ class role::backup::postgresql inherits role::backup {
         Concat["$pg_path/pg_hba.conf"],
         Concat["$pg_path/recovery.conf"],
         File["$pg_path/postgresql.conf"],
+      ],
+      subscribe => [
+        Concat["$pg_path/pg_hba.conf"],
+        Concat["$pg_path/recovery.conf"],
+        File["$pg_path/postgresql.conf"],
       ]
     }
   }
index 12fa9bb8b81cb63ca716cb644c986fd3d56d9b4a..384a41890d80a40a20ba8cb42d8a3a0f9d208e69 100644 (file)
@@ -3,5 +3,5 @@ host <%= @ldap_server %>
 base <%= @ldap_base %>
 binddn <%= @ldap_dn %>
 bindpw <%= @ldap_password %>
-pam_login_attribute <%= @ldap_attribute %>
+pam_login_attribute <%= @pgbouncer_ldap_attribute %>
 pam_filter <%= @ldap_filter %>
index bd70e0b8fb166e2220e4d0623ad1ed2be3ac7512..1e88c8943142c78a4767d2d2c68108d893bd4db2 100644 (file)
@@ -25,6 +25,9 @@ if netboot_mode is not None:
     result = client.post("/cloud/project/{}/instance/{}/rescueMode".format(project,
         instance["id"]), imageId=instance["imageId"], rescue=(netboot_mode == "rescue"))
     print(result)
+else:
+    result = client.post("/cloud/project/{}/instance/{}/reboot".format(project, instance["id"]), type="soft")
+    print(result)
 
 # reboot normal:
 #result = client.post("/cloud/project/{}/instance/{}/reboot".format(project, instance["id"]), type="soft")