Puppet Resource Ordering Examples

Puppet Logo
Today on Ubuntu 12.04 we will be looking into Puppet’s Resource Ordering! As you may know Puppet runs files in such a random way you can’t control it by writing the code in order. You have to use Puppet’s own resource ordering Metaparameters.

Metaparameters

Puppet has four different metaparameters you can use to order the running case. before, require and subscribe. Here are the examples for all of them.

before

before lists resources that depends on it, for example right now Notify required Package to be ran.

require

require is as it says a requirement, now we can put Package under Notify since we need Package to be ran in order to send the notify.

subscribe

subscribe make a resource subscribe to another resource. This means that everytime Puppet makes some actual changes to the subscribed resource it will trigger also the subscriber to do changes. On this example every time /tmp/apache -file contents change and we run this file there will be a trigger to refresh apache2 service.

Chaining

Chaining is setting resources in the ordering you’d like them to be. -> or <- goes for ordering and ~> or <~ goes for subscribing. You should always think the arrows like time. Right going arrow means the target is synced after the shooter. In this example I have made Notifications to be ran on the wrong time just to show the effectiveness.

That’s it for metaparameters, on the next one there will be modules!