0

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:

/etc/puppet/modules/net/templates/vlan.erb

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

1 Answer 1

1

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.

2
  • 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 Commented Feb 8, 2013 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. Commented Feb 8, 2013 at 13:36

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.