Added new logrotate puppet module.

Allows us to easily manage log rotation. Example:

  logrotate::file { 'xyz':
    log => '/var/log/xyz.log',
    options => ['compress', 'weekly'],
  }

Change-Id: I84fa3a20e0510a1273aa9b8555da0dde4613f50a
This commit is contained in:
David Shrewsbury 2012-05-07 16:19:07 -04:00
commit 9a04df09eb
3 changed files with 60 additions and 0 deletions

20
manifests/file.pp Normal file
View File

@ -0,0 +1,20 @@
define logrotate::file($log,
$options,
$prerotate='undef',
$postrotate='undef',
$firstaction='undef',
$lastaction='undef') {
# $options should be an array containing 1 or more logrotate
# directives (e.g. missingok, compress).
include logrotate
file { "/etc/logrotate.d/${name}":
owner => root,
group => root,
mode => 644,
content => template("logrotate/config.erb"),
require => File["/etc/logrotate.d"],
}
}

16
manifests/init.pp Normal file
View File

@ -0,0 +1,16 @@
# Adapted from http://projects.puppetlabs.com/projects/1/wiki/Logrotate_Patterns
class logrotate {
package { "logrotate":
ensure => latest,
}
file { "/etc/logrotate.d":
ensure => directory,
owner => root,
group => root,
mode => 755,
require => Package["logrotate"],
}
}

24
templates/config.erb Normal file
View File

@ -0,0 +1,24 @@
<%= log %> {
<% options.each do |opt| -%> <%= opt %>
<% end -%>
<% if prerotate != 'undef' -%>
prerotate
<%= prerotate %>
endscript
<% end -%>
<% if postrotate != 'undef' -%>
postrotate
<%= postrotate %>
endscript
<% end -%>
<% if firstaction != 'undef' -%>
firstaction
<%= firstaction %>
endscript
<% end -%>
<% if lastaction != 'undef' -%>
lastaction
<%= lastaction %>
endscript
<% end -%>
}