Ask Your Question

Is there a reasonable way to run a shell command when a file watched by puppet is changed or created?

asked 2013-06-18 14:15:25 -0600

ranceh gravatar image

When you upgrade web apps you often need to run a database script that alters the database to match the needs of the new version of the app.

We would like a way to regulate when this command is run by a puppet managed host.

We thought we could setup a file that puppet would watch and then if it was created/changed we could catch that and run the appropriate command when needed.

Now all file can do is notify a service.

I have to write a fake service to run the command when the service is notified.

Seems ... (more)

edit retag flag offensive close merge delete


I believe I do something similar for my DNS servers. Take a look at question I had asked a couple of months ago:

Red Cricket gravatar imageRed Cricket ( 2013-06-18 14:57:00 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-18 14:57:27 -0600

updated 2013-06-18 15:13:37 -0600

ramindk gravatar image

You could tie together exec and file, see an example and interesting discussion here :

in a nutshell :

file { "file1":
            recurse => true,
            owner   => "root",
            group   => "root",
            mode    => "700",
            source  => "puppet://server/file1",
            notify   => Exec["refresh_conf"],

 exec { "refresh_conf":
            command     => "exec something",
            refreshonly => 'true', # only runs when notified.

Note : if the file is not in puppet control, you might need the audit metaparameter

edit flag offensive delete link more


This looks like it should do the trick. Thanks.

ranceh gravatar imageranceh ( 2013-06-19 10:07:42 -0600 )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


Asked: 2013-06-18 14:15:25 -0600

Seen: 498 times

Last updated: Jun 18 '13