Linux – is there a way to run a command before puppet implements a change

linuxpuppet

I want to have puppet run a specific command before performing any type of change. I am aware of the prerun_command option in the main puppet.conf, but this is not what I'm looking for. I want the command to only run if something is about to change, not on every puppet run.

Here's the scenario. Let's say I have a bunch of web servers behind a load balancer. I then want puppet to update the web site files. But in order to prevent issues where some files have been updated, but other files haven't, and the mixed versions causing problems, I want to take the server out of the load balancer pool.
I could write a script which when run will tell the load balancer to remove the box from the pool. Then puppet can do the change, and use postrun_command to put the box back in the pool once complete. But I need a way to run that script to remove the server from the pool.

The only solution I can think of is to keep 2 copies of the files on the box. One a staging copy, and when puppet updates that, use a notify action to trigger the removal script, and then copy from staging into the live location. But I was hoping for something a little more generic that would work on any change being performed (upgrading a package, restarting a service, creating a user, anything).

Best Answer

Puppet's main purpose is configuration management. That is to say, it will enforce the configuration(s) you declare. What you need (based on the scenario you outlined in your question) is command and control. As @Mike points out, fabric is one option. I personally like Marionette Collective, as it is a Puppet Labs product and plays nice with the Puppet internals (facts, etc).