ssh-keygen on pg servers
authorPeter Palfrader <peter@palfrader.org>
Sun, 26 Feb 2017 21:36:17 +0000 (22:36 +0100)
committerPeter Palfrader <peter@palfrader.org>
Sun, 26 Feb 2017 21:36:17 +0000 (22:36 +0100)
modules/debian-org/lib/facter/roleaccounts.rb
modules/roles/manifests/postgresql_server.pp

index afa6f19..221c376 100644 (file)
@@ -1,6 +1,17 @@
 begin
     require 'etc'
 
+    Facter.add("postgresql_key") do
+        setcode do
+            key = nil
+            keyfile = '/var/lib/postgresql/.ssh/id_rsa.pub'
+            if FileTest.exist?(keyfile)
+                key = File.open(keyfile).read.chomp
+            end
+            key
+        end
+    end
+
     Facter.add("staticsync_key") do
         setcode do
             key = nil
index e90c27e..3fbaa63 100644 (file)
@@ -10,4 +10,11 @@ class roles::postgresql_server {
        file { "/etc/dsa/pg-backup-file.conf":
                content => template('roles/postgresql_server/pg-backup-file.conf.erb'),
        }
+
+       if ! $::postgresql_key {
+               exec { 'create-postgresql-key':
+                       command => '/bin/su - postgres -c \'mkdir -p -m 02700 .ssh && ssh-keygen -C "`whoami`@`hostname` (`date +%Y-%m-%d`)" -P "" -f .ssh/id_rsa -q\'',
+                       onlyif  => '/usr/bin/getent passwd postgres > /dev/null && ! [ -e /var/lib/postgresql/.ssh/id_rsa ]'
+               }
+       }
 }