Puppet: Convert a Variable to Lower Case



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.

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",

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.

$myname_downcase = downcase($myname)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s