I have a Puppet class that sets up a number of services and configuration files. In most cases, there is a default server that can be used, but it is also possible to configure explicit per-service servers. I find myself doing this all the time:
class myclass (
$default_server = 'server.example.com',
$server_for_thing1 = undef,
$server_for_thing2 = undef,
$server_for_thing3 = undef
) {
if $server_for_thing1 {
$real_server_for_thing1 = $server_for_thing1
} else {
$real_server_for_thing1 = $default_server
}
# ...and so forth...
}
As the number of possible services grows large, this syntax becomes unwieldy. Is there a better way of doing this? I really want something along the lines of:
$server_for_thing1 = $server_for_thing1 || $default_server
...but variables cannot be re-assigned in Puppet. Are there better ways of doing this?