Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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've written a module and I've defined a variable called "master" in the location: /etc/puppet/network/manifests/vlan/vlan.pp. In vlan.pp I make a call to a template file: file { "ifcfg-${interface}": content => template('net/vlan.erb'), } However I can't access the variable "master" in the file location:


When puppet runs on the client it doesn't get printed. My understanding would be this is a scope issue, but I'm stuck as to what the scope call should be, can someone please help me with this?

I've tried the following calls already in the erb file: <%= scope.lookupvar('network::vlan::master') %> <%= scope.lookupvar('network::vlan::vlan::master') %> <%= master %>

Thanks Dan

share|improve this question
up vote 1 down vote accepted

I would change your template to have something like:

<%= @master %>

Also make sure that in your vlan.pp you have something of the sort:

$master = "value"

The template will have whatever variables are accessible in the scope of where the template was generated. An easy way to make sure a variable is accessible in the template is to turn any variables from outside the local scope into an instance variable with something like this:

$var = $somemodule::var

Then you access the var in your template with @var.

share|improve this answer
Hi, Thanks for the reply I am setting the variable in my nodes.pp by calling the following: net::vlan::vlan { "vlan1": master => "bond0", } Then in vlan.pp I do the following: define net::vlan::vlan ( $master, ) { ... Then in my code I call a file resource with the line: content => template('network/ifcfg-vlan.erb'), } which file should I put your suggestion in? i.e the point about: $var = $somemodule::var Thanks again Dan – Dan Feb 8 '13 at 13:04
Maybe as a test, add to net::vlan::vlan ($master) { $local_master = $master, then use @local_master in your template, see if it isn't seeing the variable master properly. – lsd Feb 8 '13 at 13:36

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.