Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to puppet. As such I am trying to work my way around the best way to setup my manifests that make sense. Following the DRY (don't repeat yourself) principle, I am trying to load common directives in one template, then load in environment specific directives from a file matching the environment. Basically like this:

# nodes.pp
node base_dev {
    $service_env = 'dev'

node 'service1.ownij.lan' inherits base_dev {
    include global_env_specific    

class global_env_specific {
    include shell::bash

# modules/shell/bash.pp
class shell::bash inherits shell {

    notify{"Service env: ${service_env}": }

    file { '/etc/profile.d/':
        content => template('_global/prefix.erb', 'shell/bash/global.erb', 'shell/bash/$service_env.erb'),
        mode    => 644

But every time I run puppet agent --test puppet complains that it can't find the shell/bash/$service_env.erb file, but I double checked that it exists. I know the var is accessible due to the notify statement outputting the expected value, so I suspect I am doing which is not allowed.

I know I could have a single template.erb and pass variables to the template, which would work in this case because the file is small and not many changes across environments, but for more complex configs (httpd, solr, etc) I'd prefer to access environment specific files. I am also aware that I can specify environment specific module paths, but I'd prefer to just handle this behavior at the template level, instead of having several, closely named directories.


share|improve this question
up vote 5 down vote accepted

You are using single quotes for 'shell/bash/$service_env.erb' which means that no variables will be interpolated. You must use double quotes.

share|improve this answer
Wow, I really should have caught that... thanks. – Mike Purcell Oct 17 '12 at 22:48
I'd also wrap the variable name in curly braces to avoid ambiguity. "...${service_env}.erb" – Jeff McCune Oct 18 '12 at 15:20

Your Answer


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.