Michael Cumings
2011-Dec-07 21:17 UTC
[Puppet Users] Using a defined resource declared within a parameterized class?
I want to be able to build a parameterized class that represents each of our major services, and then use a define within that class that will make use of the parameters. For example, have a class that represents a complete application, which is a virtualenv python application. Then use a define within that application instance of the class to add pip installed packages to the virtualenv created by the parameterized class. Is this even possible? What would be the syntax? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2011-Dec-08 23:03 UTC
[Puppet Users] Re: Using a defined resource declared within a parameterized class?
On Dec 7, 3:17 pm, Michael Cumings <mcumi...@narrativescience.com> wrote:> I want to be able to build a parameterized class that represents each of > our major services, and then use a define within that class that will make > use of the parameters. For example, have a class that represents a > complete application, which is a virtualenv python application. Then use a > define within that application instance of the class to add pip installed > packages to the virtualenv created by the parameterized class. > > Is this even possible? What would be the syntax?I''m not sure whether that''s possible, but in any event it''s not necessary. The class can always forward any of its own parameters to a definition instance via its parameters, and the definition can access the class''s variables (including, I think, its parameters) by their qualified names. I recommend you separate the class and definition, and use those tools to provide data to definition instances. It will be a lot clearer. If you want to try what you described, however, then the syntax would be something like this (might not work): class example::foo ($p, $q) { # the definition: define bar ($r) { # using a definition parameter: notice { "example-${r}": # using a class parameter: message => "${q}" } # ... } # instantiate of the definition example::foo::bar { ''baz'': r => "$p" } } I have no idea whether you could successfully instantiate the definition from outside the class (making it function as a closure), but if so then you would need to be sure to declare the class first. Afterward, if it''s possible to do this at all then the same instantiation syntax I show above will work outside the class. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.