0

I am trying to create a test config for logrotate using puppet. But it seems like I am missing something as it is not creating the rotated file. My requirement is if the logfile exceeds x amount of size, it should rotate the log.

Below is the puppet code snippet.

$conf_params = {
        dateext  => true,
        compress => true,
        ifempty  => false,
        mail     => false,
        olddir   => false,
      }
      $configdir     = '/etc'
      $root_group    = 'root'
      $logrotate_bin = '/usr/sbin/logrotate'
      $base_rules = {
        'test' => {
          path         => '/root/test/logs/test.log'
          create_mode  => '0775',
          copytruncate => true,
          size         => '10M',
        },
      }
      $rule_default = {
        missingok    => true,
        create       => true,
        size         => '10M',
        create_owner => 'root',
        create_group => 'root',
}
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
sriramsm04
  • 343
  • 1
  • 7
  • 22
  • This is how my `logrotate.conf` file looks like `compress create dateext nomail noolddir notifempty rotate 4 weekly # configurable file rotations include /etc/logrotate.d` – sriramsm04 Jun 01 '18 at 21:38
  • These are only variables. You need a resource of some kind somewhere to manage the logrotate config file. – Matthew Schuchard Jun 02 '18 at 15:43

1 Answers1

1

as mentioned by https://stackoverflow.com/users/5343387/matt-schuchard you have only declared variables and have not called anything. from the example it looks like you may be trying to use the voxpupuli-logrotate module.

if so you probably dont need to set $configdir, $root_group or $logrotate_bin as the values you specify are the default for everything but FreeBSD. you cant really override the base_rules and rule_default as they are defined in a private class. that said you probably don't want to change those values and instead just set logrotate::create_base_rules: false if you dont want the default rules. Finally create your own rules by setting the logrotate::rules hash.

putting this together we have the following

$conf_params = {
  dateext  => true,
  compress => true,
  ifempty  => false,
  mail     => false,
  olddir   => false,
}
$rules = {
  'test' => {
    'path'         => '/root/test/logs/test.log',
    'create_mode'  => '0775',
    'copytruncate' => true,
    'size'         => '10M',
  }
}
class {'logrotate':
  config => $conf_params,
  rules  => $rules,
}

alternatively you can just

include logrotate

then use hiera

logrotate::config:
  dateext: true
  compress: true
  ifempty: false
  mail: false
  olddir: false
logrotate::rules
  test:
    path: /root/test/logs/test.log
    create_mode: '0775'
    copytruncate: true
    size: 10M
balder
  • 734
  • 5
  • 12