Browse Source

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
David Shrewsbury 7 years ago
commit
9a04df09eb
3 changed files with 60 additions and 0 deletions
  1. 20
    0
      manifests/file.pp
  2. 16
    0
      manifests/init.pp
  3. 24
    0
      templates/config.erb

+ 20
- 0
manifests/file.pp View File

@@ -0,0 +1,20 @@
1
+define logrotate::file($log,
2
+                       $options,
3
+                       $prerotate='undef',
4
+                       $postrotate='undef',
5
+                       $firstaction='undef',
6
+                       $lastaction='undef') {
7
+
8
+  # $options should be an array containing 1 or more logrotate
9
+  # directives (e.g. missingok, compress).
10
+
11
+  include logrotate
12
+
13
+  file { "/etc/logrotate.d/${name}":
14
+    owner => root,
15
+    group => root,
16
+    mode => 644,
17
+    content => template("logrotate/config.erb"),
18
+    require => File["/etc/logrotate.d"],
19
+  }
20
+}

+ 16
- 0
manifests/init.pp View File

@@ -0,0 +1,16 @@
1
+# Adapted from http://projects.puppetlabs.com/projects/1/wiki/Logrotate_Patterns
2
+
3
+class logrotate {
4
+
5
+  package { "logrotate":
6
+    ensure => latest,
7
+  }
8
+
9
+  file { "/etc/logrotate.d":
10
+    ensure => directory,
11
+    owner => root,
12
+    group => root,
13
+    mode => 755,
14
+    require => Package["logrotate"],
15
+  }
16
+}

+ 24
- 0
templates/config.erb View File

@@ -0,0 +1,24 @@
1
+<%= log %> {
2
+<% options.each do |opt| -%> <%= opt %>
3
+<% end -%>
4
+<% if prerotate != 'undef' -%>
5
+ prerotate
6
+  <%= prerotate %>
7
+ endscript
8
+<% end -%>
9
+<% if postrotate != 'undef' -%>
10
+ postrotate
11
+  <%= postrotate %>
12
+ endscript
13
+<% end -%>
14
+<% if firstaction != 'undef' -%>
15
+ firstaction
16
+  <%= firstaction %>
17
+ endscript
18
+<% end -%>
19
+<% if lastaction != 'undef' -%>
20
+ lastaction
21
+  <%= lastaction %>
22
+ endscript
23
+<% end -%>
24
+}

Loading…
Cancel
Save