7

In my puppet config I need to lowercase a variable value before using it in a template. How to achieve this? Is there a way to lowercase a variable value inside the puppet manifest? Do I need to do this in the template?

And more general: where are string manipulation functions that I could use in manifests.

Do I have to write my own custom ruby functions to achieve this?

Franklin Piat
  • 736
  • 6
  • 22
paweloque
  • 257
  • 1
  • 4
  • 10

2 Answers2

16

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

Jeff McCune
  • 358
  • 1
  • 5
13

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 %>
Shane Madden
  • 112,982
  • 12
  • 174
  • 248