Puppet: Convert a Variable to Lower Case

noted-felt-puppets-1

 

This is going to be a very simple example of how to convert a variable to all lowercase inside a Puppet module.

If you look, which I am sure that you have already…there seems to be a lot of documentation around how to use the Ruby “downcase” function, but not much of it is easy to read if you are not very familiar with Ruby.

In this example, I create a very simple Puppet module and show how to use the downcase function.

[code language=”css”]
class test-module (
$myname = "TEST",
){

$myname_downcase = downcase($myname)

file { "/var/tmp/$myname_downcase":
ensure => present,
content => "This is a Test File for $myname_downcase",
}
}
[/code]

In this example I have a Variable called $myname. I am setting $myname to TEST inside the init.pp.

Note however you would probably never do this. More than likely you would do one of the following:

  1. Set $myname so that it is an external environmental variable
  2. Set $myname to NULL and override in Foreman.

The meat in this potato is this line here, where we take the $myname variable and munge it into a new variable called $myname_downcase.

[code language=”css”]

$myname_downcase = downcase($myname)

[/code]

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.