How to access variable in puppet

configurationpuppet

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

Best Answer

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.

Related Topic