From 8d3aa0b52cb03b467f3b01451de44f6524cb3447 Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Fri, 21 Aug 2015 09:43:23 +0200 Subject: [PATCH 1/9] Added possibility to define package state Added possibility to define package state and made it 'present' by default instead of the hardcoded 'latest'. --- manifests/base.pp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manifests/base.pp b/manifests/base.pp index 706a0d43..650f7638 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -3,9 +3,11 @@ # Examples # # include logrotate::base -class logrotate::base { +class logrotate::base ( + $package_state = 'present' +){ package { 'logrotate': - ensure => latest, + ensure => $package_state, } File { From 4e19aa4ce0574734f90a0c82c986b5b1b6afa6cd Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Fri, 21 Aug 2015 09:57:27 +0200 Subject: [PATCH 2/9] Updated rspec based on new default value Updated rspec based on new default value for package logrotate ensure which is now 'present' instead of 'latest'. --- spec/classes/base_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/classes/base_spec.rb b/spec/classes/base_spec.rb index 933b481d..9d1cb4de 100644 --- a/spec/classes/base_spec.rb +++ b/spec/classes/base_spec.rb @@ -2,7 +2,7 @@ describe 'logrotate::base' do it do - should contain_package('logrotate').with_ensure('latest') + should contain_package('logrotate').with_ensure('present') should contain_file('/etc/logrotate.conf').with({ 'ensure' => 'file', From 30586e5dc89e62b5eb92888e17a6e43ddcb716ed Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Mon, 23 May 2016 10:48:02 +0200 Subject: [PATCH 3/9] Adding logrotate.conf template Adding logrotate.conf template to have greater control over base configuration. --- templates/etc/logrotate.conf.erb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 templates/etc/logrotate.conf.erb diff --git a/templates/etc/logrotate.conf.erb b/templates/etc/logrotate.conf.erb new file mode 100644 index 00000000..d6d4e8d3 --- /dev/null +++ b/templates/etc/logrotate.conf.erb @@ -0,0 +1,25 @@ +# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET. ANY CHANGES WILL BE +# OVERWRITTEN. + +# Default values +# rotate log files weekly +weekly + +# keep 4 weeks worth of backlogs +rotate <%= @rotate %> + +# create new (empty) log files after rotating old ones +create + +<% if @compress -%> +compress +<%- end -%> + +<% if @dateext -%> +# use date as a suffix of the rotated file +dateext +<%- end -%> + + +# packages drop log rotation information into this directory +include /etc/logrotate.d From 76d765729a3cf0cf080213f6bd3e39537c85181f Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Mon, 23 May 2016 10:50:53 +0200 Subject: [PATCH 4/9] Using logrotate.conf template with class parameters --- manifests/base.pp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manifests/base.pp b/manifests/base.pp index 650f7638..a459bb06 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -4,7 +4,9 @@ # # include logrotate::base class logrotate::base ( - $package_state = 'present' + $dateext = false, + $package_state = 'present', + $rotate = 4 ){ package { 'logrotate': ensure => $package_state, @@ -20,7 +22,7 @@ '/etc/logrotate.conf': ensure => file, mode => '0444', - source => 'puppet:///modules/logrotate/etc/logrotate.conf'; + content => template('logrotate/etc/logrotate.conf.erb'),; '/etc/logrotate.d': ensure => directory, mode => '0755'; From af7472bce792d1677ddb95d753c69c3ad8171770 Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Mon, 23 May 2016 10:51:17 +0200 Subject: [PATCH 5/9] Phasing out static file replaced by template --- files/etc/logrotate.conf | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 files/etc/logrotate.conf diff --git a/files/etc/logrotate.conf b/files/etc/logrotate.conf deleted file mode 100644 index 2cdc6f61..00000000 --- a/files/etc/logrotate.conf +++ /dev/null @@ -1,15 +0,0 @@ -# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET. ANY CHANGES WILL BE -# OVERWRITTEN. - -# Default values -# rotate log files weekly -weekly - -# keep 4 weeks worth of backlogs -rotate 4 - -# create new (empty) log files after rotating old ones -create - -# packages drop log rotation information into this directory -include /etc/logrotate.d From 9782691db8185ed990f4cbc8b4d946a86d399b88 Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Mon, 23 May 2016 11:03:40 +0200 Subject: [PATCH 6/9] Corrected in line comment --- templates/etc/logrotate.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/etc/logrotate.conf.erb b/templates/etc/logrotate.conf.erb index d6d4e8d3..cfe0c81e 100644 --- a/templates/etc/logrotate.conf.erb +++ b/templates/etc/logrotate.conf.erb @@ -5,7 +5,7 @@ # rotate log files weekly weekly -# keep 4 weeks worth of backlogs +# keep X weeks worth of backlogs rotate <%= @rotate %> # create new (empty) log files after rotating old ones From 68f37cfdb99858cf3c7fa45167c0de54969906f7 Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Tue, 24 May 2016 12:52:05 +0200 Subject: [PATCH 7/9] Introducing support for custom compression method --- manifests/base.pp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manifests/base.pp b/manifests/base.pp index a459bb06..c96d14d6 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -4,6 +4,8 @@ # # include logrotate::base class logrotate::base ( + $compresscmd = undef, + $compressext = undef, $dateext = false, $package_state = 'present', $rotate = 4 From 4b82645bb0954cbac1f8374ccb4ee750d9f57458 Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Tue, 24 May 2016 12:56:34 +0200 Subject: [PATCH 8/9] Introducing support for custom compression method --- templates/etc/logrotate.conf.erb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/templates/etc/logrotate.conf.erb b/templates/etc/logrotate.conf.erb index cfe0c81e..cfc4f916 100644 --- a/templates/etc/logrotate.conf.erb +++ b/templates/etc/logrotate.conf.erb @@ -15,6 +15,14 @@ create compress <%- end -%> +<% if @compresscmd -%> +compresscmd <%= @compresscmd %> +<%- end -%> + +<% if @compressext -%> +compressext <%= @compressext %> +<%- end -%> + <% if @dateext -%> # use date as a suffix of the rotated file dateext From c5c0428c74c24f01dc12affbc59515437fee8be5 Mon Sep 17 00:00:00 2001 From: Benjamin Merot Date: Tue, 24 May 2016 13:06:52 +0200 Subject: [PATCH 9/9] Added missing compress value by default --- manifests/base.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/base.pp b/manifests/base.pp index c96d14d6..87948f43 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -4,6 +4,7 @@ # # include logrotate::base class logrotate::base ( + $compress = true, $compresscmd = undef, $compressext = undef, $dateext = false,