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.


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.


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


  • 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

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.