Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
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? –  Shane Madden Feb 21 '13 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 '13 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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

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.