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?


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 %>
| improve this answer | |

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.