3

I often want to include default values in Puppet templates. I was hoping that given a class like this:

class myclass ($a_variable=undef) {
  file { '/tmp/myfile':
    content => template('myclass/myfile.erb'),
  }
}

I could make a template like this:

a_variable = <%= a_variable || "a default value" %>

Unfortunately, undef in Puppet doesn't translate to a Ruby nil value in the context of the template, so this doesn't actually work. What is the canonical way of handling default values in Puppet templates?

I can set the default value to an empty string and then use the empty? test...

a variable = <%= a_variable.empty? ? "a default value" : a_variable %>

...but that seems a little clunky.

larsks
  • 47,453

1 Answers1

2

Couldn't you just set a default in the class definition?

class myclass ($a_variable = "a default value") {
Shane Madden
  • 116,404
  • 13
  • 187
  • 256