0

I've defined a hash like so in my nodes.pp:

net::addr { "eth5": rt => { rt1 => { address => '192.168.10.0', netmask => '255.255.255.0', gateway => '192.5.28.19', src => '192.5.28.21' }, } 

What I can't get to access is the title of the hash in my templates, so I want to print out the title of the hash i.e. "eth5", how can I do that? Also I have a variable called $int in my define class in the file for my module (/etc/puppet/modules/net/addr.pp), how can I access that using the scope.lookupvar function from this template in the same module?

Thanks Dan

2
  • In the case of that example, the eth5 is the title of the resource being defined, not related to the hash variable being used as a parameter to the resource - can you clarify how this this fits in with the defined type you're using? Commented Feb 21, 2013 at 7:41
  • Hi Shane, I'm using the following in my class: define addr::net ($route={},){$int = $name file { "routes-${name}": ensure => 'present', mode => '0655', owner => 'root', group => 'root', path=> "/opt/routes/route-${name}", content => template('net/routes-temp.erb'),}. In my templates file I can't don't know how to access this $int or $name variable from my templates alternatively how would I access the title from my template? Thanks Dan Commented Feb 21, 2013 at 9:36

2 Answers 2

0

The variables set in the defined type are available as local scope variables to the contents of a template.

Simply using <%= title %> or <%= int %> in the template should be using the variable that was set for that specific instance of the defined type.

0

In your example, you should be using the namevar, $name.

For example, if you define a resource like this:

objecttype { "namevar": parameter=>"value" } 

Then the variables will be set thusly:

$name = "namevar" $parameter = "value" 

Within templates called from the define, these can be simply referred to a $name and $parameter (but watch out for reserved words!).

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.