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 would like to know if it is possible to lookup the value of another Puppet resource, something like the following example:

define foo( $username ) {
    $home = User[$username].home
    ....
}

The above syntax does not work, but that is probably because I don't know Ruby well enough.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

As far as I know, this is not possible. Originally, Puppet used dynamic scoping for variables, but it was deprecated as of 2.7.0. See more information here about what you should do instead.

In this particular case, however, I don't think plain scoping will do. In fact, I think you should use either virtual resources or exported resources. They are both very similar, actually, except that exported resources work inter-hosts.

Either way, you'll just have to structure your code in a very different way than what you want to do, it seems to me. Spend some time looking at complex puppet modules and understand how they go about doing what they do.

share|improve this answer

Puppet have its own language, it doesn't use Ruby. You can define a resource as belows:

define add_user ( $uid ) {
    $username = $title
    user { $username:
        home    => "/home/$username",
        shell   => "/bin/bash",
        uid     => $uid
    }
}

and call it with:

add_user { tom:
    uid      => 501
}

Read more...

share|improve this answer
    
I know, but I would like to be able to have some function call in another definition which, in your example, returns "/home/tom". –  muksie Aug 30 '11 at 16:00
    
Could you please explain a little more about your situation? –  quanta Aug 30 '11 at 17:09

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.