Frederic Beuserie
2007-Nov-23 10:17 UTC
what''s the best way to deal with class/inheritence
sorry to cross post to dev/users. -dev was not the best option ;-) Hi to all puppet masters: functionnality I need is quite simple: classes/ one .pp file per class, example: class mail-gateway { ...service/host/templates... definitions } -> this should set all that''s needed to setup a given system "rôle" in the system (installing packages, config files with variables (templates) ...) --> currently it''s defined as a ''class mail-gateway { $var1="value1"; include other_sub_classes; package machin, ... }'' bundle/ one .pp file defining a "bundle" of system rôles. this allow field engineer to say: this host is a "remote office" type of server, a "mail gateway", ... and then a list of classes is installed (from classes/ using include statements) in a convenient and easy way --> currently it''s defined as a ''class bundle-xxxx { $var1="value2"; include other_classes }'' site-global.pp only one pp containing values for a given site installation (multiple server, one customer, for example) --> currently it''s defined as a ''node site-globals { $var1="value3" }'' nodes/ "node xxx" statements, one by individual physical server. --> currently it''s defined as a ''node xxxx inherits site-global { $var1="value4"; include bundle-yyyy }'' this is working quite well BUT for the variables parts. I''m completely missing is how I can define at each level variables with inheritences in a GOOD way - 1 classes/mail-gateway.pp -> classes defaults, very generic (but working) ones -> this should be value1 - 2 bundle/remote-office-server.pp -> bundle defaults, working ones in the context of the bundle -> this should be value2 - 3 site-globals.pp -> i need a way to specify variables available to all nodes/ machines and these will be overriden but level 4 variables if needed. -> this should be value3 - 4 nodes/server1.pp -> server real and customized values -> this should be value4 in real world: - 1 and 2 will be used to install a "standard" machines, with default and functionnal values but with NO customs example: dns_server=$isp_dns_server - 3 will contains variables for the entire site to be installed and that will be used for all nodes in this site (unless overidden in the node) example: dns_server=$this_client_existing_ms_active_directory_dns_server - 4 non site-default values for this given host. example: dns_server=$special_dns_server_for_this_host. i''ve tried many combination of "node xxx inherits yyy", "include classes", "include classes { key => value }", "global" and classes specific variables, ... never reached to required functionnalities. every times something breaks. what i need is advice/example/know issues/... to points me on the RIGHT way to do these kind of setup. Is me taking the problem by the wrong side or this kind of setup no possible with the current state of puppet ? And i know puppet is a declarative language, but that''s it, i only want to "declare" values, config files and group them in a some convenient way for others (field engineer/install lab engineer) to deal with it. i''ve read a lot of articles but find no solutions, inheritence examples on the puppet docs are not dealing with these multiple level of inheritence.. perhaps this should even be a faq ? thanks -- /* Frederic Beuserie * FOSS Technical Leader * Alunys */ _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
David Schmitt
2007-Nov-23 10:34 UTC
Re: what''s the best way to deal with class/inheritence
Frederic Beuserie schrieb:> sorry to cross post to dev/users. -dev was not the best option ;-) > > Hi > > to all puppet masters: > > functionnality I need is quite simple: > > classes/ > one .pp file per class, example: class mail-gateway { ...service/host/templates... definitions } > -> this should set all that''s needed to setup a given system "rôle" in the system (installing packages, config files with variables (templates) ...) > --> currently it''s defined as a ''class mail-gateway { $var1="value1"; include other_sub_classes; package machin, ... }'' > > bundle/ > one .pp file defining a "bundle" of system rôles. this allow field engineer to say: this host is a "remote office" type of server, a "mail gateway", ... > and then a list of classes is installed (from classes/ using include statements) in a convenient and easy way > --> currently it''s defined as a ''class bundle-xxxx { $var1="value2"; include other_classes }'' > > site-global.pp > only one pp containing values for a given site installation (multiple server, one customer, for example) > --> currently it''s defined as a ''node site-globals { $var1="value3" }'' > > nodes/ > "node xxx" statements, one by individual physical server. > --> currently it''s defined as a ''node xxxx inherits site-global { $var1="value4"; include bundle-yyyy }'' > > this is working quite well BUT for the variables parts. > I''m completely missing is how I can define at each level variables with inheritences in a GOOD way > > - 1 classes/mail-gateway.pp -> classes defaults, very generic (but working) ones > -> this should be value1 > > - 2 bundle/remote-office-server.pp -> bundle defaults, working ones in the context of the bundle > -> this should be value2 > > - 3 site-globals.pp -> i need a way to specify variables available to all nodes/ machines > and these will be overriden but level 4 variables if needed. > -> this should be value3 > > - 4 nodes/server1.pp -> server real and customized values > -> this should be value4 > > in real world: > - 1 and 2 will be used to install a "standard" machines, with default and functionnal values but with NO customs > example: dns_server=$isp_dns_server > > - 3 will contains variables for the entire site to be installed and that will be used for all nodes in this site (unless overidden in the node) > example: dns_server=$this_client_existing_ms_active_directory_dns_server > > - 4 non site-default values for this given host. > example: dns_server=$special_dns_server_for_this_host. > > i''ve tried many combination of "node xxx inherits yyy", "include classes", "include classes { key => value }", "global" and classes specific variables, ... > > never reached to required functionnalities. every times something breaks. > > what i need is advice/example/know issues/... to points me on the RIGHT way to do these kind of setup. > > Is me taking the problem by the wrong side or this kind of setup no possible with the current state of puppet ? > And i know puppet is a declarative language, but that''s it, i only want to "declare" values, config files and group them in a some convenient way > for others (field engineer/install lab engineer) to deal with it. > > i''ve read a lot of articles but find no solutions, inheritence examples on the puppet docs are not dealing with these multiple level of inheritence.. > perhaps this should even be a faq ?You might want to take a look at "template classes" in the Glossary[1]. Additionally I would recommend to setup a explicit hierarchy of defaults: i.e. in the final resource: $dns_server_real = coalesce($dns_server, $dns_server_site_default, $dns_server_bundle_default, $dns_server_global_default) Where "coalesce" returns the first non-empty value. Matt and others probably would recommend setting up defines and overriding the parameters on inheritance. While this too is a valid approach I do not have much experience with it and therefore refrain from further comments. [1] http://reductivelabs.com/trac/puppet/wiki/GlossaryOfTerms Regards, DavidS