Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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


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.