I'm using R10K with Puppet. The Puppetfile
is basically DSL:
Because the Puppetfile format is actually implemented using a Ruby DSL any valid Ruby expression can be used.
Ref: https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd
So based on that, I can write some Ruby code in the Puppetfile
. I tried and it does work. But what I don't find and know, is how to access some variables.
Ultimately, I'm trying to do something like this:
mod 'app',
:git => 'https://github.com/apps/app.git',
:branch => ${environment}
Such that the module branch that is checked out is the same as the environment for which it is checked out. Obviouslt ${environment}
isn't the right syntax and isn't a real variable name.
So the best answer to this question would be how to get a variable of the environment and the second best answer would be how to reference a variable (and what variables are available) in the Puppetfile
.
Of course, 10 minutes after I ask the question, I figured out the answer (been trying to solve this for hours)...
In the
Puppetfile
you have access to the variables of theDSL
class (see DSL class in GitHub. Thus you have access to@librarian
which is an instance of thePuppetfile
class (see puppetfile.rb). And from there, you have access to its attributes.So the answer to getting a branch of the name of the current environment is:
Not elegant and I wish the
puppetfile.rb
would give us a direct access to the environment but that works for me.