Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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 %>
share|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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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