From: Ismaƫl Bouya Date: Fri, 17 Aug 2018 10:51:33 +0000 (+0200) Subject: Add cat_files report to notify of important changes X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=a7b985dd3cc4af68875733eb135335a31504f472;p=perso%2FImmae%2FProjets%2FPuppet.git Add cat_files report to notify of important changes --- diff --git a/environments/global/common.yaml b/environments/global/common.yaml index 3cc75fa..97bf196 100644 --- a/environments/global/common.yaml +++ b/environments/global/common.yaml @@ -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 index 0000000..9d9c068 --- /dev/null +++ b/modules/base_installation/lib/puppet/reports/cat_files.rb @@ -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 + diff --git a/modules/base_installation/manifests/init.pp b/modules/base_installation/manifests/init.pp index d8abcaf..a1b5ca8 100644 --- a/modules/base_installation/manifests/init.pp +++ b/modules/base_installation/manifests/init.pp @@ -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 diff --git a/modules/base_installation/manifests/params.pp b/modules/base_installation/manifests/params.pp index 5ade838..f336b65 100644 --- a/modules/base_installation/manifests/params.pp +++ b/modules/base_installation/manifests/params.pp @@ -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", diff --git a/modules/base_installation/manifests/puppet.pp b/modules/base_installation/manifests/puppet.pp index 10b3773..603a961 100644 --- a/modules/base_installation/manifests/puppet.pp +++ b/modules/base_installation/manifests/puppet.pp @@ -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 - } } } diff --git a/modules/base_installation/templates/puppet/puppet.conf.erb b/modules/base_installation/templates/puppet/puppet.conf.erb index da39468..38a0c1b 100644 --- a/modules/base_installation/templates/puppet/puppet.conf.erb +++ b/modules/base_installation/templates/puppet/puppet.conf.erb @@ -1,6 +1,6 @@ [main] <% - reports = ["store"] + reports = ["store", "cat_files"] if @xmpp.count > 0 reports << "xmpp" end