Define a postrun command for puppet runs
authorJan Dittberner <jandd@cacert.org>
Tue, 13 Aug 2019 10:17:48 +0000 (12:17 +0200)
committerJan Dittberner <jandd@cacert.org>
Tue, 13 Aug 2019 10:17:48 +0000 (12:17 +0200)
sitemodules/profiles/files/base/etckeeper_post_command.sh [new file with mode: 0644]
sitemodules/profiles/manifests/base.pp

diff --git a/sitemodules/profiles/files/base/etckeeper_post_command.sh b/sitemodules/profiles/files/base/etckeeper_post_command.sh
new file mode 100644 (file)
index 0000000..ec10155
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+set -e
+
+if etckeeper unclean; then
+       if ! etckeeper commit "saving uncommitted changes in /etc after puppet run"; then
+               echo "warning: etckeeper failed to commit changes in /etc using $VCS" >&2
+       fi
+fi
index 69e369f..2a7aad2 100644 (file)
@@ -237,4 +237,27 @@ class profiles::base (
       ensure => absent,
     }
   }
+
+  package { 'etckeeper':
+    ensure => installed,
+  }
+  file { '/etc/etckeeper/post-puppet.d':
+    ensure  => directory,
+    owner   => 'root',
+    group   => 'root',
+    mode    => '0755',
+    require => Package['etckeeper'],
+  }
+  file { '/etc/etckeeper/post-puppet.d/50uncommitted-changes':
+    ensure => file,
+    owner  => 'root',
+    group  => 'root',
+    mode   => '0755',
+    source => 'puppet://modules/profiles/base/etckeeper_post_command.sh',
+  }
+
+  augeas { 'set_puppet_postrun_command':
+    context => '/etc/puppetlabs/puppet/puppet.conf',
+    changes => 'set main/postrun_command "etckeeper post-puppet"',
+  }
 }