Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notify if Puppet wants to change something

Tags:

puppet

I am currently working on implementing Puppet in our environment, and I have a request I don’t know if Puppet itself can fulfill:

If I have a configuration file at /etc/myconfig.conf, and I want it to be written only if it does not already exist, then I could achieve that via an exec resource’s onlyif parameter. But is there any way that I can get Puppet to do something like a notify if it detects a change in a file?

I don’t want it to actually change the file, only to notify me that the file is not the way I want it to be.

Although there are no examples in this question, I hope someone is able to push me in the right direction here. If I create a solution for this based on tips, I will post the answer myself for others to learn from.

like image 881
xeor Avatar asked Sep 20 '25 03:09

xeor


2 Answers

For only creating a file if it doesn't exist, try setting replace to false, like so:

file { "/etc/myconfig.conf":
  ensure => present,
  source => "puppet:///modules/${module_name}/myconfig.conf",
  replace => false,
}

Docs for that are here: http://docs.puppetlabs.com/references/2.7.0/type.html#file

For the notification, puppet auditing will do what you need: http://puppetlabs.com/blog/all-about-auditing-with-puppet/

like image 105
Justintime Avatar answered Sep 23 '25 10:09

Justintime


It sounds like you want puppet to alert you of any changes it WOULD do rather than do them.

For this, just run with noop (--noop)

it will tell you every change it is going to do but not perform them.

like image 45
Bezerker Avatar answered Sep 23 '25 12:09

Bezerker