Hi Tom, This definitely seems like a job for parameterized classes. This language feature allows you to define your model while expressing some parameters (data) that your model will use to modify its behavior.
In your node definitions, you'd declare parameterized clases like resources. http://docs.puppetlabs.com/learning/modules2.html#parameters class { 'module::component': systemtype => 'foobar', } When it comes to 'looping' through things, the Puppet DSL does not yet have an iterator or other like operators. We do have something called defined resource types. The end-result looks like a regular resource but it's 'defined' from a collection of other resource types that you can pass data into. It's great for modeling something complex that you can interact with via a simplified resource interface. Here's a doc on the subject: http://docs.puppetlabs.com/learning/definedtypes.html Once you have a defined resource type that gives you the looping behavior you're looking for, I suggest that you 'declare' one or more of these resources in your classes (like module::component). You can then use the parameterized class mechanism to pass in data to all the resources in your classes, including those that you have defined. Hope that makes sense and good luck! --Ryan On Thu, Mar 14, 2013 at 10:55 PM, Tom Melendez <t...@supertom.com> wrote: > Hi Folks, > > Like to get some advice on module organization. I have a system that > has a few different components. One or more components can be > installed on a host. The hosts also have a "type" dimension. This > "type" dimension could (should) ideally be used to configure the > system (fill in a bunch of variables). Problem is, I'm not sure how > the best way to do this in puppet. > > I'm running puppet 2.7x. > > To illustrate, I'd like to do something like this (pseudo syntax): > > node 'foo.example.com' { > include module::component("systemType" => "foobar") > include module::component2("systemType" => "foobar") > } > > node 'foo2.example.com' { > include module::component("systemType" => "foobar2") > include module::component3("systemType" => "foobar2") > } > > or, maybe even better > > node 'foo.example.com' { > include module(components => [component1,component2], "systemType" > => "foobar") > } > > node 'foo2.example.com' { > include module(components => [component1,component3], "systemType" > => "foobar2") > } > > In the above illustration, the value of componentType can determine > which files to load, as well as a bunch of variables (40-60 variables) > which would be used for things like ensuring directories are present, > ownership, users installed, etc.. > > I was thinking that each component would be a class, which is fine in > itself, but my real problem is the movement of these variables > (configuration). There are a lot of components, and enough variables > that I don't want to add them to each class. I want to be able to do > something like: > > class mymodule(components, componentType) { > $myconfig = getConfig($componentType) > # can I "loop" through components? > include mymodule::component($myconfig) > } > > Hopefully that's descriptive enough. Feel free to ask questions. > Ultimately, my major goal is to boil the configuration down to a > single location, as the configurations (systemTypes). Some like this > would work (I think) if calling the class could be dynamic: > > http://docs.puppetlabs.com/guides/parameterized_classes.html#appendix-smart-parameter-defaults > > Thanks in advance for the feedback, > > Tom > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to puppet-users+unsubscr...@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Ryan Coleman | Modules & Forge | @ryanycoleman | ryancoleman in #puppet -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.