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

Is there a way to (a) accept arbitrary arguments to a class or resource definition and then (b) pass those arguments on to another class or resource definition?

I often find that what I am writing is a thin wrapper over a native type or over a third-party module. For example:

define myconfigfile {
  file { "/path/to/$name":
    owner => lars,
    group => lars,

That is, myconfigfile is effectively shorthand for a set of file resources with a known prefix. I would actually like myconfigfile to accept the same parameters as the file resource type (such as content, source, etc), but I would like to avoid:

define myconfigfile (
  $content = undef,
  $source = undef
) {

This works okay when there are only one or two parameters, but it becomes unmanageable if I am trying to wrap a parameterized class with lots of parameters.

share|improve this question

One possibility would be to use a hash to pass in an arbitrary list of parameters.

Another, and perhaps better option would be to make use of the Ruby DSL which allows you to use Ruby instead of the Puppet language.

There are a variety of examples available as well.

Essentially, you would pass in the hashmap then use Ruby's iteration/looping (the ruby hash object has a .each method) to extract the key-value pairs from the hash.

The Ruby DSL became available in 2.6.x.

share|improve this answer
And then what? I've used hash parameters for templates in the past, but I'm not sure how to best make use of them for the situation described in my question. – larsks Jun 28 '12 at 13:39
You'd have to know what was passed in, so it would be somewhat difficult. It's a shame that puppet doesn't have better iteration in it's language, outside of templates. – Lee Lowder Jun 28 '12 at 17:58
Updated the answer, so it actually provides an solution now. – Lee Lowder Jun 29 '12 at 15:55
The Ruby DSL has been deprecated. – chutz Apr 2 '14 at 11:38

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.