Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to implement a custom recursive directory synchronization resource in Puppet. What I need to do is the following.

I have a YAML file with the list of hostnames and the list of directories that should exist on each hostname inside, say, /var/lib/my_app directory (deployment.yml):

  - DIR_1
  - DIR_5
  - DIR_7
  - DIR_2
  - DIR_3
  - DIR_9

On the master I have a directory that contains all of those DIR_* sub-directories. Each subdirectory contains some files. What I'm trying to achieve is to synchronize all the nodes according to the deployment.yml, so that /var/lib/my_app on host_1 only contains DIR_1 and DIR_5, but does not contain DIR_7, DIR_2, DIR_3, DIR_9, and so on.

I tried to do this using the ignore variable for file type, but this does not remove the directories from the node if I remove them from deployment.yml. I tried to write a custom function to remove them afterwards, but it does not seem to work inside my manifest. I also wanted to implement a custom type, but it seems to be too complicated.

I'd appreciate any help on this.

share|improve this question

Have a look at the 'purge' parameter for the file type. You would set this at the file resource for /var/lib/my_app.

Snippet from "puppet describe file":

- **purge**
    Whether unmanaged files should be purged. This option only makes
    sense when managing directories with `recurse => true`.

    * When recursively duplicating an entire directory with the `source`
      attribute, `purge => true` will automatically purge any files
      that are not in the source directory.
    * When managing files in a directory as individual resources,
      setting `purge => true` will purge any files that aren't being
      specifically managed.

    If you have a filebucket configured, the purged files will be uploaded,
    but if you do not, this will destroy data.  Valid values are `true`,
share|improve this answer
You need to be careful that you don't have some files in the dirs that you don't want managed, because they will be purged also. It basically says that in the snippet above, but people seem to skip it (including me). – lsd Feb 4 '13 at 13:43
@Ger Apeldoorn To be able to do this with purge I need to pass the list of subdirectories I want to exist to source, but I'm not sure I can do this. – Andriy Yurchuk Feb 4 '13 at 15:39
up vote 0 down vote accepted

I've ended up implementing this with Ruby DSL

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.