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

net::addr { "eth5":
        rt => {
                rt1 => {
                        address => '',
                        netmask => '',
                        gateway => '',
                        src     => ''

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

  • 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? 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
    – Dan
    Feb 21, 2013 at 9:36

2 Answers 2


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.


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!).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.