Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 am setting up a dirvish backup system using puppet. Dirvish has the concept of a vault - a self-contained directory which contains the backup data and the configuration for what and how to backup. These vaults can be anywhere in the filesystem, so you need to explicitly list them in the master dirvish config file.

The way I have done this with puppet duplicates the information about the vaults, by first creating them as resources, and then passing a array of vault names to the master dirvish resource.

  # Dirvish vaults, alphabetically sorted
  dirvish::vault { 'server-a-full':
    client      => 'server-a',
    tree        => '/',
    backup_root => $dirvish_backup_root

  dirvish::vault { '':
    client       => 'server-b',
    tree         => '/srv/www/vhosts/',
    rsync_option => '--copy-unsafe-links',
    backup_root  => $dirvish_backup_root

  # TODO - we duplicate the vault definitions here, but I don't 
  # see a better way right now
  class {'dirvish': 
    backup_root => $dirvish_backup_root,
    vaults      => ['server-a-full', '']

The dirvish::vault class looks something like this

define dirvish::vault($tree, $client, $exclude = [], $rsync_option = '', $backup_root) {
  file {"$backup_root/$name/dirvish/default.conf":
    ensure => present,
    content => template("dirvish/vault.conf.erb"),
    require => File["$backup_root/$name/dirvish"]

The dirvish class uses the vaults variable in a template

<% vaults.each do |vault| -%>
        <%= vault %>
<% end -%>

How can I remove this duplication?

share|improve this question
Possibly related to… – Robert Munteanu May 13 '14 at 8:38
What do you do with the titles of the dirvish::vault resources? – Artefacto May 13 '14 at 8:50
@Artefacto - I've updated the question with that info, basically creates a file on disk and the intermediate directories ( elided from question, for brevity ) – Robert Munteanu May 13 '14 at 9:01
I meant what does the class do with the vault titles you pass to it? – Artefacto May 13 '14 at 9:09
@Artefacto - passes it straight to a template – Robert Munteanu May 13 '14 at 9:59

If you move your configuration data to Hiera, the template can use the same data as whatever class declares the actual dirvish::vaults.

E.g., create a structure that lends itself to use with create_resources:

  backup_root: "<backup-root-value>"

    client: 'server-a',
    tree: '/',
    client: 'server-b',
    tree: '/srv/www/vhosts/',
    rsync_option: '--copy-unsafe-links',

And in the manifest:

create_resources('dirvish::vault', hiera('dirvish_vaults'), hiera('dirvish_vault_defaults'))

The template can load the same hash and iterate its keys etc.

share|improve this answer

I think your best option is to use a concat module, like this or some split config, if dirvish supports it (each vault would create its own config file which would then be included in the main config). It's possible to peek into the catalog with the spaceship operator, but that would only allow you to set the order between the resources or set properties of the vaults inside the class. It's not possible to do something like $vaults = Dirvish::Vault <| |>.

As a last resort, you can also hack something in ruby. The type instance seems to be passed the catalog early in the run, in autorequire. You can save the reference at that point an do nasty things afterwards.

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.