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? :(

fge
  • 318
  • 2
  • 6

1 Answers1

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, } 
}
Stijn Hoop
  • 258
  • 1
  • 6
kashani
  • 3,922
  • 19
  • 18
  • 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