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?
If you move your configuration data to Hiera, the template can use the same data as whatever class declares the actual
dirvish::vault
s.E.g., create a structure that lends itself to use with create_resources:
And in the manifest:
The template can load the same hash and iterate its keys etc.
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.