From c8511b2019b44360887d33a9626ec14c81736aee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 11 May 2018 12:54:22 +0200 Subject: [PATCH] Add slack notification for puppet --- .gitmodules | 3 +++ external_modules/slack | 1 + modules/base_installation/manifests/puppet.pp | 8 ++++++++ .../templates/puppet/puppet.conf.erb | 15 ++++++++++----- .../templates/puppet/slack.yaml.erb | 12 ++++++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) create mode 160000 external_modules/slack create mode 100644 modules/base_installation/templates/puppet/slack.yaml.erb diff --git a/.gitmodules b/.gitmodules index 357cc1d..0f21622 100644 --- a/.gitmodules +++ b/.gitmodules @@ -61,3 +61,6 @@ [submodule "modules/redis"] path = external_modules/redis url = git://git.immae.eu/github/arioch/puppet-redis +[submodule "external_modules/slack"] + path = external_modules/slack + url = git://git.immae.eu/github/cegeka/puppet-slack diff --git a/external_modules/slack b/external_modules/slack new file mode 160000 index 0000000..5abc090 --- /dev/null +++ b/external_modules/slack @@ -0,0 +1 @@ +Subproject commit 5abc0909a05b6665d94c63771ab81620aecc1f28 diff --git a/modules/base_installation/manifests/puppet.pp b/modules/base_installation/manifests/puppet.pp index 3ca226a..05fe9a1 100644 --- a/modules/base_installation/manifests/puppet.pp +++ b/modules/base_installation/manifests/puppet.pp @@ -82,6 +82,7 @@ class base_installation::puppet ( } $xmpp = lookup("base_installation::notify_xmpp", { "default_value" => {} }) + $slack = lookup("base_installation::notify_slack", { "default_value" => {} }) file { "$base_installation::puppet_conf_path/puppet.conf": content => template("base_installation/puppet/puppet.conf.erb"), @@ -95,6 +96,13 @@ class base_installation::puppet ( } } + unless empty($slack) { + file { "$base_installation::puppet_conf_path/slack.yaml": + content => template("base_installation/puppet/slack.yaml.erb"), + require => File[$base_installation::puppet_conf_path], + } + } + if file("$base_installation::puppet_conf_path/host_ldap.info", "/dev/null") != "" and empty($facts["ldapvar"]) { fail("LDAP was activated but facts are not available") diff --git a/modules/base_installation/templates/puppet/puppet.conf.erb b/modules/base_installation/templates/puppet/puppet.conf.erb index 03b33bb..da39468 100644 --- a/modules/base_installation/templates/puppet/puppet.conf.erb +++ b/modules/base_installation/templates/puppet/puppet.conf.erb @@ -1,9 +1,14 @@ [main] -<% if @xmpp.count > 0 %> -reports = store,xmpp -<% else %> -reports = store -<% end %> +<% + reports = ["store"] + if @xmpp.count > 0 + reports << "xmpp" + end + if @slack.count > 0 + reports << "slack" + end +%> +reports = <%= reports.join(",") %> basemodulepath = <%= @puppet_code_path %>/modules:<%= @puppet_code_path %>/external_modules diff --git a/modules/base_installation/templates/puppet/slack.yaml.erb b/modules/base_installation/templates/puppet/slack.yaml.erb new file mode 100644 index 0000000..bcfb9f8 --- /dev/null +++ b/modules/base_installation/templates/puppet/slack.yaml.erb @@ -0,0 +1,12 @@ +--- +:slack_webhook: '<%= @slack["webhook"] %>' +:slack_channel: '<%= @slack["channel"] %>' +:slack_username: '<%= @slack["username"] %>' +:slack_icon_url: '<%= @slack["icon_url"] %>' +:slack_statuses: +<% @slack["statuses"].each do |status| %> + - <%= status %> +<% end %> +:foreman_api_host: ~ +:puppetboard_api_host: ~ + -- 2.41.0