How to make a variable in a parameterized Puppet class default to the value of another parameter?
Solution 1:
While not exactly what you are asking for, have you considered using an External Node Classifier to set and override the default value for specific servers? I believe the ECN is the "puppet way" of doing things in a situation like yours.
EDIT: (based on the first comment)
Second idea: you can use a custom function to at least make the multi-line repeated logic a bit more readable. Something like this, which returns the first "defined" argument, though with puppet, I am never sure what "defined" is (in this case, "undef" gets passed as an empty string to the function, which is still good enough).
module Puppet::Parser::Functions
newfunction(:get_default, :type => :rvalue) do |args|
value = nil
args.each { |x|
if ! x.nil? and x.length > 0
value = x
break
end
}
return value
end
end
You can then call it as many times as you want:
$real_server_for_thing1 = get_default($server_for_thing1, $default_server)
$real_server_for_thing2 = get_default($server_for_thing2, $default_server)
$real_server_for_thing3 = get_default($server_for_thing3, $default_server)