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 diff --git a/manifests/base.pp b/manifests/base.pp index 706a0d43..87948f43 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -3,9 +3,16 @@ # Examples # # include logrotate::base -class logrotate::base { +class logrotate::base ( + $compress = true, + $compresscmd = undef, + $compressext = undef, + $dateext = false, + $package_state = 'present', + $rotate = 4 +){ package { 'logrotate': - ensure => latest, + ensure => $package_state, } File { @@ -18,7 +25,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'; 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', diff --git a/templates/etc/logrotate.conf.erb b/templates/etc/logrotate.conf.erb new file mode 100644 index 00000000..cfc4f916 --- /dev/null +++ b/templates/etc/logrotate.conf.erb @@ -0,0 +1,33 @@ +# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET. ANY CHANGES WILL BE +# OVERWRITTEN. + +# Default values +# rotate log files weekly +weekly + +# keep X weeks worth of backlogs +rotate <%= @rotate %> + +# create new (empty) log files after rotating old ones +create + +<% if @compress -%> +compress +<%- end -%> + +<% if @compresscmd -%> +compresscmd <%= @compresscmd %> +<%- end -%> + +<% if @compressext -%> +compressext <%= @compressext %> +<%- 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