Lowercase variable values in a Puppet template

Solution 1:

Puppet's string manipulation capabilities inside manifests are very limited. Manifests aren't really intended to handle stuff like this.

But, in the template, it's easy; normal ruby functions are available. Say I wanted a lowercase of the osfamily fact:

<%= osfamily.downcase %>

Solution 2:

There are two general solutions I can think of for this problem. By general, I mean they'll work in manifest files and templates instead of just templates.

The solution I recommend is to use the downcase() parser function in the standard library module. I recommend this because you don't need to write any ruby code and it's easier to read:

class helloworld {
  $os_downcase = downcase($osfamily)
}
include helloworld

If you don't want to depend on the stdlib module, then you can use the inline_template function to generalize the solution Shane mentioned:

class helloworld {
  $os_downcase = inline_template('<%= osfamily.downcase %>')
}
include helloworld

inline_template avoids the need to create a separate *.erb file.

Hope this helps. -Jeff