Ask Your Question
0

Puppet conditional notification

asked 2017-07-23 16:01:21 -0500

Dziki_Jam gravatar image

updated 2017-07-23 16:01:33 -0500

Is there any way to make Puppet output a message only if a specific file was changed?

file { $config_file:
    ensure  => file,
    owner   => $config_owner,
    group   => $config_group,
    mode    => '0444',
    content => template('testmodule/test.yaml.erb'),
} ->

notify {"You might need to restart Puppet Server in order changes to be applied.":}
edit retag flag offensive close merge delete

Comments

There are examples in the documentation that do what you are trying to do: https://docs.puppet.com/puppet/5.0/lang_relationships.html

Red Cricket gravatar imageRed Cricket ( 2017-07-23 19:39:57 -0500 )edit

You could probably do something of the following : put a notify to a class called alerter or something. The class would hold the alert. notify => Class['profile::alerter'] class profile::alerter { notify("blorgo") }

negast gravatar imagenegast ( 2017-07-24 03:48:28 -0500 )edit

Using the 'audit' capability of a file, you can even have puppet notify on a change to a file's content that is not managed by puppet, using the same notification mechanism above. However, if something needs restarted on file change, you should just have puppet restart it on file change

DarylW gravatar imageDarylW ( 2017-07-24 08:07:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-07-24 05:48:35 -0500

I created a test module - shout.pp - it creates the file /tmp/fred - it runs the exec only if file changes - and sends message via exec if it has, Previously I probably would have used the audit option but I believe this is deprecated now.

class shout {
    file { '/tmp/fred':
    ensure  => file,
    content => "FRED",
    mode    => '0600',
    owner   => 'root',
    group   => 'root',
    notify  => Exec['stuff'],
   }
  exec { 'stuff':
    command => '/bin/echo "Fred has changed"',
    refreshonly => true,
  }
}
include shout



puppet apply shout.pp 
Notice: Compiled catalog for pclient.localdomain in environment production in 0.12 seconds
Notice: Finished catalog run in 0.06 seconds
-_- root@pclient ~ $ echo "TEST" >> /tmp/fred
-_- root@pclient ~ $ !p
puppet apply shout.pp 
Notice: Compiled catalog for pclient.localdomain in environment production in 0.13 seconds
Notice: /Stage[main]/Shout/File[/tmp/fred]/content: content changed '{md5}b1ad547e69225dbf3cfe0f955764d08b' to '{md5}ffb61f7d3dad0c9901007888548591f8'
Notice: /Stage[main]/Shout/Exec[stuff]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.18 seconds
-_- root@pclient ~ $ !!
puppet apply shout.pp 
Notice: Compiled catalog for pclient.localdomain in environment production in 0.12 seconds
Notice: Finished catalog run in 0.06 seconds
-_- root@pclient ~ $
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-07-23 16:01:21 -0500

Seen: 74 times

Last updated: Jul 24