puppet

Notify if Puppet wants to change something


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.


Solution

  • 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/