Ask Your Question
0

How to write puppet logs on each client to be re-written/appended to a central log file for one particular module?

asked 2017-04-05 06:03:33 -0500

monalsharma gravatar image

I have a puppet master/client arch deployed in the company. We are already deploying 150+ puppet modules in the environment.

I have been asked to create a puppet module to install/update a package and create a log every time it upgrades/installs on a client. This log has to be written to a central log outside the client.

Is there any way I can achieve this using Puppet? Can some code be included in the module itself to do this or do I need to run a script outside of Puppet to get the logs from each client?

Currently, we are logging all Puppet runs in /var/log/puppet/puppet.log on each client.

Please suggest.

Thanks, Monal

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-04-06 06:46:38 -0500

puser gravatar image

Something simple to do this would be:

package { 'mypackage':
  ensure => latest,
  notify => [ Exec['logger'], Exec['local_logger'] ],
}

exec { 'local_logger':
  command => 'echo "YYYMMDD : package has been updated" >> /path/to/local/log/file',
  refreshonly => true,
  before => Exec['logger']
}

exec { 'logger':
  command => "tail -10 /path/to/log/file | ssh ${my_log_server} 'cat >> /path/to/log/master'"
  refreshonly => true,
}

Only when the package mypackage fires it will run the exec local_logger first which will add the log entry locally. The exec logger will tail the contents of your log file and ssh the contents to the server with the master log file.

I do not particularly like exec resources too much and i'm sure there is a module out there that you could use or write that would do the same.

edit flag offensive delete link more

Comments

Thanks a lot. This really helps.

monalsharma gravatar imagemonalsharma ( 2017-04-10 01:10:08 -0500 )edit
0

answered 2017-04-06 09:59:39 -0500

DarylW gravatar image

Do you use puppetdb? If you externally know what the package name is, you could probably mine that information using psql from the puppetdb instance, instead of requiring a 'push' type log to keep track of it.

note: I haven't used puppetdb or psql, but I think you would either have some of that information already available either in puppetdb, or in your puppet config print reportdir directory, in my case that is /var/lib/puppet/reports. Under that directory is a folder per host, and inside of each folder is the results of each run (in yaml). You and read those values for the package in question and produce a report. There is probably a better way to make actual reports for things you care about directly from you master ( https://docs.puppet.com/puppet/4.9/fo... )

edit flag offensive delete link more

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: 2017-04-05 06:03:33 -0500

Seen: 40 times

Last updated: Apr 06