Running a command when a file is updated

It's a very common pattern to have Puppet take some action whenever a particular file is updated. For example, in the rsync config snippet example, each snippet file called an exec to update the main rsyncd.conf file when it changed.

An exec resource will normally be run every time Puppet runs, unless you specify one of the following parameters:

  • creates
  • onlyif
  • unless
  • refreshonly => true

The refreshonly parameter means that the exec should only be run if it receives a notify from another resource (such as a file, for example).

Getting ready…

Install the nginx package (actually, we just want the stock config file, but this is the easiest way to get it):

# apt-get install nginx

How to do it…

  1. Create a new module nginx ...

Get Puppet 2.7 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.