1

I'm still fairly new to puppet, and am now at the point where I want to use classes with parameters in my custom modules.

I have a module called tsvpuppet, and I want it to act as a wrapper to the mysql module with standard paramters (maybe later on based on custom facts fromt he host).

in my /etc/puppet/modules/tsvmysql/manifests/init.pp file

class tsvmysql {
     class { '::mysql::server':
            root_password    => 'password',
            override_options => $override_options
           }
}

The above module code seems to work, but classes in classes just feels wrong.

Can anyone suggest a better way of writing this, or suggest how it should be done ?

Many thanks.

Matt

Matt
  • 153
  • 2
  • 8
  • 2
    I dont see anything wrong with that. if you are going to instantiate a class in puppet you either do what you did, `class {}` syntax, or `include ::mysql::server` syntax. If you use the `include` syntax you cannot pass parameters to it without using `hiera`. `include` can be slightly safer since if it is included already in another class it won't do anything. `class {}` syntax will bomb out if it exists somewhere else. – ptierno Dec 04 '14 at 23:48
  • Thankyou, that explains why I couldn't see how to use include with paramters. As most of the paramters will be coming from custom facts I have written, I think I'll need to stick with multiple classes, and a single include as below. Thanks for your help. – Matt Dec 05 '14 at 10:09

1 Answers1

1

You can include the class ::mysql::server.

class tsvmysql {
   include '::mysql::server'
}

class { '::mysql::server':
            root_password    => 'password',
            override_options => $override_options
}
BMW
  • 42,880
  • 12
  • 99
  • 116
  • I really like this, it makes sense, and fits in perfectly with what i'm trying to achieve. Many thanks! – Matt Dec 05 '14 at 10:10