9

Puppet must hate me. I have been reading the doc for hours on end and still cannot manage to achieve the following:

  • a class or module (or what is it called) with a variable in it (a parameterized class?);
  • this class to be included multiple times in a single host.

In pseudo-code, that would be:

# The class
classorwhatever myclass ($value) {
    notify { "$value world" }
}

# In the node definition
node whatever {
    myclass("Hello")
    myclass("Goodbye")
}

I feel so stupid it is not even funny. I know it must be doable. But how? :(

13

You can only use a parameterized class once. If you plan to hit a node several times with a function while varying the data definitions are the way to go.

example

class apache ( $module ) {
  if module = ssl then and so on
}

define apache::vhost ($priority=99) {
  file { "apache/vhost.d/${name}":
    content => template("apache/vhosts/$name.erb"),
  }
}

node webserver {
  class { 'apache': module => 'ssl', }
  apache::vhost { 'www': priority => 00, }
  apache::vhost { 'test': priority => 99, } 
}
  • Excellent. fwiw #puppet on freenode and the mail lists are very active and have covered things like this in depth. If you're just getting started with Puppet I'd suggest keep both those resources on hand. – kashani Jan 19 '12 at 21:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.