Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
You are reading this? docs.puppetlabs.com/learning/modules2.html. What vrsion of puppet is on your server/client? –  Zoredache Jan 18 '12 at 17:07
    
@Zoredache 2.6.12 on both the server and clients –  fge Jan 18 '12 at 22:13

1 Answer 1

up vote 6 down vote accepted

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, } 
}
share|improve this answer
    
Thanks, I was able to achieve what I wanted at last! –  fge Jan 19 '12 at 8:21
    
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

 
discard

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.