Puppet Class: logrotate

Defined in:
manifests/init.pp

Summary

Install and configure log rotation on Linux

Overview

Management of ‘/etc/logrotate.conf` is performed as edits to avoid clobbering vendor defaults.

The module takes the position that the files laid down by the vendor are correct and only modifies them the minimal amount needed to make the system work - users/admins are trusted not alter files away from the defaults.

Examples:

Install logrotate with vendor configuration

include logrotate

Hiera default settings

logrotate::settings:
  weekly:
  rotate: 4
  create:
  dateext:
  compress:

Hiera logrotate entries (custom rules)

lograte::entries:
  /var/log/messages:
  /var/log/myapp:
    settings:
      rotate: 50

Parameters:

  • package (String) (defaults to: "logrotate")

    Name of the package providing ‘logrotate`

  • settings (Hash[String,Any]) (defaults to: {})

    Hash of default settings for ‘logrotate.conf` (see examples)

  • entries (Hash[String,Hash[String,Any]]) (defaults to: {})

    Hash of logrotate entries to create (see examples)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'manifests/init.pp', line 30

class logrotate(
  String                        $package    = "logrotate",
  Hash[String,Any]              $settings   = {},
  Hash[String,Hash[String,Any]] $entries    = {},
) {

  package { $package:
    ensure => present,
  }

  $settings.each |$key, $opts| {
    $value = pick_default($opts, "")

    fm_replace { "/etc/logrotate.conf:${key}":
      ensure            => present,
      path              => "/etc/logrotate.conf",
      data              => "${key} ${value}",
      match             => logrotate::find_match($key),
      insert_if_missing => true,
    }
  }

  $entries.each |$key,$opts| {
    logrotate::entry { $key:
      * => $opts,
    }
  }
}