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.

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/custom_test.sh':
        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 custom.sh 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.

Thanks.

share|improve this question

1 Answer 1

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 M Oct 18 '12 at 15:20

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.