]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add cat_files report to notify of important changes
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 17 Aug 2018 10:51:33 +0000 (12:51 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 17 Aug 2018 10:56:19 +0000 (12:56 +0200)
environments/global/common.yaml
modules/base_installation/lib/puppet/reports/cat_files.rb [new file with mode: 0644]
modules/base_installation/manifests/init.pp
modules/base_installation/manifests/params.pp
modules/base_installation/manifests/puppet.pp
modules/base_installation/templates/puppet/puppet.conf.erb

index 3cc75fa561b1545bcf23a7c95d365f2a11f90e97..97bf19637c18dfd195f6dbb14458ee1f353e544b 100644 (file)
@@ -21,8 +21,8 @@ base_installation::ldap_dn: "cn=%{facts.ec2_metadata.hostname},ou=hosts,dc=immae
 base_installation::ldap_cn: "%{facts.ec2_metadata.hostname}"
 base_installation::ldap_server: "ldap.immae.eu"
 base_installation::ldap_uri: "ldaps://ldap.immae.eu"
-# FIXME: get all mounts without needing that hack?
 base_installation::puppet_conf_path: "/etc/puppetlabs/puppet"
+base_installation::puppet_notifies_path: "/etc/puppetlabs/notifies"
 base_installation::puppet_code_path: "/etc/puppetlabs/code"
 base_installation::puppet_pass_seed: "/etc/puppetlabs/puppet/password_seed"
 base_installation::puppet_ssl_path: "/etc/puppetlabs/ssl"
@@ -30,6 +30,7 @@ base_installation::system_locales: ["fr_FR.UTF-8", "en_US.UTF-8"]
 base_installation::system_timezone: "Europe/Paris"
 base_installation::system_users: [] # Fetched via ldap
 base_installation::notify_xmpp: {}
+# FIXME: get all mounts without needing that hack?
 profile::fstab::mounts:
   - "%{facts.ldapvar.self.vars.mounts.0}"
   - "%{facts.ldapvar.self.vars.mounts.1}"
diff --git a/modules/base_installation/lib/puppet/reports/cat_files.rb b/modules/base_installation/lib/puppet/reports/cat_files.rb
new file mode 100644 (file)
index 0000000..9d9c068
--- /dev/null
@@ -0,0 +1,17 @@
+require 'puppet'
+
+Puppet::Reports.register_report(:cat_files) do
+  FOLLOWED_RESOURCES = [
+    "File[/etc/puppetlabs/notifies/host_ldap.info]",
+  ]
+
+  def process
+    self.resource_statuses.each do |name, status|
+      if FOLLOWED_RESOURCES.include?(status.resource) && status.events.any? { |e| e.status == "success" }
+        puts File.open(status.title, "r").read()
+      end
+    end
+  end
+
+end
+
index d8abcaf5ac4e06794b579c4f36361a2083001086..a1b5ca8412d30ad097233a1591485f956e0cc76e 100644 (file)
@@ -1,20 +1,21 @@
 class base_installation (
-  Optional[String]        $grub_device      = $base_installation::params::grub_device,
-  Optional[String]        $ldap_base        = $base_installation::params::ldap_base,
-  Optional[String]        $ldap_cert_path   = $base_installation::params::ldap_cert_path,
-  Optional[String]        $ldap_cn          = $base_installation::params::ldap_cn,
-  Optional[String]        $ldap_dn          = $base_installation::params::ldap_dn,
-  Optional[String]        $ldap_server      = $base_installation::params::ldap_server,
-  Optional[String]        $ldap_uri         = $base_installation::params::ldap_uri,
-  Optional[String]        $puppet_code_path = $base_installation::params::puppet_code_path,
-  Optional[String]        $puppet_conf_path = $base_installation::params::puppet_conf_path,
-  Optional[String]        $puppet_pass_seed = $base_installation::params::puppet_pass_seed,
-  Optional[String]        $puppet_ssl_path  = $base_installation::params::puppet_ssl_path,
-  Optional[String]        $real_hostname    = $base_installation::params::real_hostname,
-  Optional[String]        $system_hostname  = $base_installation::params::system_hostname,
-  Optional[Array[String]] $system_locales   = $base_installation::params::system_locales,
-  Optional[String]        $system_timezone  = $base_installation::params::system_timezone,
-  Optional[Array[Hash]]   $system_users     = $base_installation::params::system_users,
+  Optional[String]        $grub_device          = $base_installation::params::grub_device,
+  Optional[String]        $ldap_base            = $base_installation::params::ldap_base,
+  Optional[String]        $ldap_cert_path       = $base_installation::params::ldap_cert_path,
+  Optional[String]        $ldap_cn              = $base_installation::params::ldap_cn,
+  Optional[String]        $ldap_dn              = $base_installation::params::ldap_dn,
+  Optional[String]        $ldap_server          = $base_installation::params::ldap_server,
+  Optional[String]        $ldap_uri             = $base_installation::params::ldap_uri,
+  Optional[String]        $puppet_code_path     = $base_installation::params::puppet_code_path,
+  Optional[String]        $puppet_conf_path     = $base_installation::params::puppet_conf_path,
+  Optional[String]        $puppet_notifies_path = $base_installation::params::puppet_notifies_path,
+  Optional[String]        $puppet_pass_seed     = $base_installation::params::puppet_pass_seed,
+  Optional[String]        $puppet_ssl_path      = $base_installation::params::puppet_ssl_path,
+  Optional[String]        $real_hostname        = $base_installation::params::real_hostname,
+  Optional[String]        $system_hostname      = $base_installation::params::system_hostname,
+  Optional[Array[String]] $system_locales       = $base_installation::params::system_locales,
+  Optional[String]        $system_timezone      = $base_installation::params::system_timezone,
+  Optional[Array[Hash]]   $system_users         = $base_installation::params::system_users,
 ) inherits base_installation::params {
   contain ::base_installation::packages
   contain ::base_installation::locales
index 5ade838ae0b70430a9ad2b9a6ea2428dcfb86ad0..f336b658bcfdd2566e2235859cc63d714abdf43c 100644 (file)
@@ -1,20 +1,21 @@
 class base_installation::params {
-  $puppet_code_path = "/etc/puppetlabs/code"
-  $puppet_conf_path = "/etc/puppetlabs/puppet"
-  $puppet_pass_seed = "/etc/puppetlabs/puppet/password_seed"
-  $puppet_ssl_path  = "/etc/puppetlabs/ssl"
-  $grub_device      = "/dev/sda"
-  $ldap_base        = "dc=example,dc=com"
-  $ldap_cn          = "node"
-  $ldap_dn          = "cn=node,ou=hosts,dc=example,dc=com"
-  $ldap_cert_path   = "/etc/ssl/certs/ca-certificates.crt"
-  $ldap_uri         = "ldaps://ldap.example.com"
-  $ldap_server      = "ldap.example.com"
-  $real_hostname    = "example.com"
-  $system_hostname  = "example.com"
-  $system_locales   = ["en_US.UTF-8"]
-  $system_timezone  = "UTC"
-  $system_users     = [
+  $puppet_code_path     = "/etc/puppetlabs/code"
+  $puppet_conf_path     = "/etc/puppetlabs/puppet"
+  $puppet_notifies_path = "/etc/puppetlabs/notifies"
+  $puppet_pass_seed     = "/etc/puppetlabs/puppet/password_seed"
+  $puppet_ssl_path      = "/etc/puppetlabs/ssl"
+  $grub_device          = "/dev/sda"
+  $ldap_base            = "dc=example,dc=com"
+  $ldap_cn              = "node"
+  $ldap_dn              = "cn=node,ou=hosts,dc=example,dc=com"
+  $ldap_cert_path       = "/etc/ssl/certs/ca-certificates.crt"
+  $ldap_uri             = "ldaps://ldap.example.com"
+  $ldap_server          = "ldap.example.com"
+  $real_hostname        = "example.com"
+  $system_hostname      = "example.com"
+  $system_locales       = ["en_US.UTF-8"]
+  $system_timezone      = "UTC"
+  $system_users         = [
     {
       userid   => 1000,
       username => "example",
index 10b3773041bd7b54356243546340eb76f2c1f05c..603a96115b97493f9f4d71af639c059ed6537c60 100644 (file)
@@ -103,45 +103,47 @@ class base_installation::puppet (
       }
     }
 
-    if file("$base_installation::puppet_conf_path/host_ldap.info", "/dev/null") != "" and
+    if file("$base_installation::puppet_notifies_path/host_ldap.info", "/dev/null") != "" and
       empty($facts["ldapvar"]) {
         fail("LDAP was activated but facts are not available")
     }
 
+    file { $base_installation::puppet_notifies_path:
+      ensure  => directory,
+      require => [Package["puppet"], Package["gem:xmpp4r"], Package["gem:ruby-ldap"]],
+      recurse => true,
+      purge   => true,
+      force   => true,
+    }
+
     $ips = lookup("ips", { 'default_value' => undef })
-    concat { "$base_installation::puppet_conf_path/host_ldap.info":
+    concat { "$base_installation::puppet_notifies_path/host_ldap.info":
       ensure         => "present",
       mode           => "0600",
-      require        => File[$base_installation::puppet_conf_path],
-      notify         => Notify_refresh["notify-ldap-password"],
+      require        => File[$base_installation::puppet_notifies_path],
       ensure_newline => true,
     }
 
     concat::fragment { "host_ldap add top":
-      target  => "$base_installation::puppet_conf_path/host_ldap.info",
+      target  => "$base_installation::puppet_notifies_path/host_ldap.info",
       content => template("base_installation/puppet/host_ldap_add_top.info.erb"),
       order   => "00-01",
     }
     concat::fragment { "host_ldap add bottom":
-      target  => "$base_installation::puppet_conf_path/host_ldap.info",
+      target  => "$base_installation::puppet_notifies_path/host_ldap.info",
       content => "EOF",
       order   => "00-99",
     }
 
     concat::fragment { "host_ldap mod top":
-      target  => "$base_installation::puppet_conf_path/host_ldap.info",
+      target  => "$base_installation::puppet_notifies_path/host_ldap.info",
       content => template("base_installation/puppet/host_ldap_mod_top.info.erb"),
       order   => "01-01",
     }
     concat::fragment { "host_ldap mod bottom":
-      target  => "$base_installation::puppet_conf_path/host_ldap.info",
+      target  => "$base_installation::puppet_notifies_path/host_ldap.info",
       content => "EOF",
       order   => "01-99",
     }
-
-    notify_refresh { "notify-ldap-password":
-      message     => template("base_installation/puppet/host_ldap.info.erb"),
-      refreshonly => true
-    }
   }
 }
index da394686c7aa97f626c32f63fedf95ecf3df9907..38a0c1bb5e21f60214e179c291033edcce45f4b9 100644 (file)
@@ -1,6 +1,6 @@
 [main]
 <%
-  reports = ["store"]
+  reports = ["store", "cat_files"]
   if @xmpp.count > 0
     reports << "xmpp"
   end