Ask Your Question
1

Module yo61/puppet-logrotate -- define multiple paths for the same logrotate::rule

asked 2016-10-12 08:12:08 -0500

Yeayu gravatar image

Hello,

I am having issues defining multiple file paths on the same logrotate rule by making use of the module: link:yo61/puppet-logrotate Looking at a default syslog logrotate file on any standard RH/CentOS box, you will see something along these lines:

/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

I am trying to manage the content of that file using logrotate::rules, but I don't seem to be able to define multiple paths (i.e. an array) in the path parameter... I could define the path as: '/var/log/*', however i would like to be more precise...

Is there anyway to do it?

Thanks in advance

edit retag flag offensive close merge delete

Comments

You don't want to use /var/log/* because that will imply rotating your log files that have already been rotated (such as messages.1.gz). /var/log/*log is acceptable, however.

bschonecker gravatar imagebschonecker ( 2016-10-12 08:38:41 -0500 )edit

// , @bschonecker, that last option is what we use. I'm glad to see you find it acceptable

NathanBasanese gravatar imageNathanBasanese ( 2017-07-11 16:51:10 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-10-12 08:46:01 -0500

bschonecker gravatar image

updated 2016-10-12 08:48:21 -0500

The following worked just fine for me:

  include logrotate
  logrotate::rule { 'foo_bar_baz_logs':
      path     =>  ['/var/log/foo.log', '/var/log/bar.log', '/var/log/baz.log', ], 
      compress => true,
   }

Resultant logrotate conf file:

[root@test logrotate.d]# cat /etc/logrotate.d/foobarbaz_logs

# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET.  ANY CHANGES WILL BE
# OVERWRITTEN.

 /var/log/foo.log /var/log/bar.log /var/log/baz.log {
   compress
 }
edit flag offensive delete link more

Comments

Many thanks, that did it. I was defining the quotes for the whole array instead of for the paths defined. I'd like though to see whether its possible to define each path in a different line, instead of concatenating them using a space...

Yeayu gravatar imageYeayu ( 2016-10-12 09:17:14 -0500 )edit

I am going to answer my own question: You can do that by amending the logrotate.d/rule.erb erb template and replace @path.join(' ') with @path.join("\n")

Yeayu gravatar imageYeayu ( 2016-10-12 09:49:41 -0500 )edit

// , This worked for me, as well. Also, for what it's worth, in the actual logrotate definition on the disk, the paths can be on different lines. They may also contain * for globbing.

NathanBasanese gravatar imageNathanBasanese ( 2017-07-11 16:50:19 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-10-12 08:12:08 -0500

Seen: 107 times

Last updated: Oct 12 '16