Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 { 'server-b-example.com':
    client       => 'server-b',
    tree         => '/srv/www/vhosts/example.com/backup',
    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', 'server-b-example.com']
  }

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

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

How can I remove this duplication?

share|improve this question
    
Possibly related to serverfault.com/questions/366088/… –  Robert Munteanu May 13 at 8:38
    
What do you do with the titles of the dirvish::vault resources? –  Artefacto May 13 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 at 9:01
    
I meant what does the class do with the vault titles you pass to it? –  Artefacto May 13 at 9:09
    
@Artefacto - passes it straight to a template –  Robert Munteanu May 13 at 9:59
add comment

2 Answers 2

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:

dirvish_vault_defaults:
  backup_root: "<backup-root-value>"

dirvish_vaults:
  'server-a-full':
    client: 'server-a',
    tree: '/',
  'server-b-example.com':
    client: 'server-b',
    tree: '/srv/www/vhosts/example.com/backup',
    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
add comment

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
add comment

Your Answer

 
discard

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.