Hello, I have a class called website, which requires both httpd and mysqld classes. Without defining it within the site.pp (node section). Is it possible to define that "website" requires these additions? Such as; class website inherits httpd, mysqld { ... } -- 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+unsubscribe@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.
On Mon, Mar 18, 2013 at 7:48 PM, JamieC <jamiecressey89@googlemail.com> wrote:> Is it possible to > define that "website" requires these additions? Such as; > > class website inherits httpd, mysqld { > > ... > > }Yes. Try: class website { ... require => Class[''httpd'', ''mysqld''] } I personally prefer more fine-grained dependencies though: class website { ... require => Service[''httpd'', ''mysqld''] } The idea here is that you don''t require the class itself, but require some resource declared in that class. I''ve assumed here that each of your classes declares a service for their respective daemon. See also http://docs.puppetlabs.com/puppet/3/reference/lang_relationships.html#syntax Regards, Matt. -- 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+unsubscribe@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.
Better practice is to expose the functionality of those classes through defines or parameterized classes. For instance, use a define like apache::vhost in the puppetlabs/apache module: https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp That way, all you have to do is use the define (no need to include or require the apache class at all), and all the relationships are handled internally in the apache module. Similarly, a define that allows you to create a database instead of a class that just installs mysql. This has the benefit of being reusable easily for different purposes and it also keeps you from having to have internal knowledge of the apache and mysql modules to make use of them. Otherwise, you still have to know *how* things are done in the apache and mysql modules, when really you just want a website or a database. On Monday, March 18, 2013 2:34:18 PM UTC-6, Matthew Burgess wrote:> > On Mon, Mar 18, 2013 at 7:48 PM, JamieC <jamiecr...@googlemail.com<javascript:>> > wrote: > > > Is it possible to > > define that "website" requires these additions? Such as; > > > > class website inherits httpd, mysqld { > > > > ... > > > > } > > Yes. Try: > > class website { > ... > require => Class[''httpd'', ''mysqld''] > } > > I personally prefer more fine-grained dependencies though: > > class website { > ... > require => Service[''httpd'', ''mysqld''] > } > > The idea here is that you don''t require the class itself, but require > some resource declared in that class. I''ve assumed here that each of > your classes declares a service for their respective daemon. > > See also > http://docs.puppetlabs.com/puppet/3/reference/lang_relationships.html#syntax > > Regards, > > Matt. >-- 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+unsubscribe@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.
On Monday, March 18, 2013 2:48:11 PM UTC-5, JamieC wrote:> > Hello, > > I have a class called website, which requires both httpd and mysqld > classes. Without defining it within the site.pp (node section). Is it > possible to define that "website" requires these additions? Such as; > > class website inherits httpd, mysqld { > > ... > > } > >You have a completely wrong idea of what class inheritance is for in Puppet. Its appropriate uses are in fact very narrow. The natural and idiomatic expression of what you describe is this: class website { include ''httpd'' include ''mysqld'' ... } That approach would be better form even if class website needed only one other class to be applied. Note also that that does not in itself say anything about the *order* in which resources are applied to clients; rather, it says that all nodes to which the ''website'' class is assigned also have the ''httpd'' and ''mysqld'' classes assigned to them. If you need ordering relationships among these then there are additional steps you can take. You certainly do not need a define to express the concept you asked about, although you can do it that way, too. Whether a defined type instance or a class is more appropriate for your particular case would involve an analysis of your use of the class, but the fact that you can do what you want with a class at all is a strong argument for a class being the right thing to use. John -- 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+unsubscribe@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.
On Monday, March 18, 2013 3:34:18 PM UTC-5, Matthew Burgess wrote:> > > Yes. Try: > > class website { > ... > require => Class[''httpd'', ''mysqld''] > } > >Nope. You are confusing separate concepts and separate language structures. The OP is defining his class, not declaring it. The ''require'' metaparameter would be applicable to a parameterized-style class * declaration*: class { ''website'': require => Class[''httpd'', ''mysqld''] }. But that wouldn''t say what the OP wants to say. Specifically, it does not (itself) say that nodes to which class ''website'' is assigned also get classes ''httpd'' and ''mysqld''; instead, it says that latter two classes -- which are *assumed* to have been assigned somehow -- should be applied to the node before class ''website'' is applied. John -- 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+unsubscribe@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.