Defined Type: logrotate::entry
- Defined in:
- manifests/entry.pp
Summary
Create a log rotate entry under `/etc/logrotate.d`.Overview
Config file to write is guessed by taking the basename of ‘log_file` unless `config_file` is passed explicitly (eg `/var/log/yum.log` would create a file at `/etc/logrotate.d/yum.log`).
Logrotate will take settings from the main configuration file at ‘/etc/logrotate.conf` unless they are individually overriden in the `settings` hash
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'manifests/entry.pp', line 43
define logrotate::entry(
Optional[String] $config_file = undef,
Optional[String] $log_file = undef,
Hash[String, Any] $settings = {},
String $header = "# managed by puppet, do not edit!",
) {
$_settings = $settings.map |$key, $value| {
" ${key} ${value}"
}.sort.join("\n")
$_log_file = pick($log_file, $title)
if $log_file {
# if log file specified, use the title as the default config file name
$_config_file = pick($config_file, $title, "${basename($log_file)}")
} else {
# otherwise the title is probably the logfile to include in the config file...
$_config_file = pick($config_file, "${basename($_log_file)}")
}
file { "/etc/logrotate.d/${_config_file}":
ensure => file,
owner => "root",
group => "root",
mode => "0644",
content => "${header}\n${_log_file} {\n${_settings}\n}"
}
}
|