My first public-facing deployment of Puppet is likely to be on some parallel computing nodes we have here. One of our fluid dynamics packages expects to be able to rsh from one master node to other slave nodes in the same batch queue. I think I''ve made some good class definitions up to this last point, where code duplication rears its head. Example of the problem: class ch405-host inherits dual-boot-cluster-host { $myqueue = ''ch405'' file { "/etc/hosts.equiv": source => "puppet://$pserver/files/apps/rsh-server/hosts.equiv.$myqueue", owner => root, group => root, mode => 644, require => Package[rsh-server], } } class ch406-host inherits dual-boot-cluster-host { $myqueue = ''ch406'' file { "/etc/hosts.equiv": source => "puppet://$pserver/files/apps/rsh-server/hosts.equiv.$myqueue", owner => root, group => root, mode => 644, require => Package[rsh-server], } } node ch405a, ch405b, ch405c, ch405d, ch405e, ch405f, ch405g, ch405h, ch405i, ch405j, ch405k, ch405l, ch405m, ch405n { include ch405-host } node ch406a, ch406b, ch406c, ch406d, ch406e, ch406f, ch406g, ch406h, ch406i, ch406j, ch406k, ch406l, ch406m, ch406n { include ch406-host } So the end result is that all ch405* nodes get the same hosts.equiv file, and all ch406* nodes get a different hosts.equiv file. Where should I look to get rid of the duplicated code? -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
On May 25, 2007, at 2:59 PM, Mike Renfro wrote:> > So the end result is that all ch405* nodes get the same hosts.equiv > file, and all ch406* nodes get a different hosts.equiv file. Where > should I look to get rid of the duplicated code?The main strategy is to create a single class with the file copy in it (possibly put it into the ''rsh'' class or something), then find a way to select the best queue outside that class. There are a couple of strategies for this. One way is to set tags and use those: node ch406, .... { tag(ch406) } Then test the tags: class rsh { if tagged(ch406) { $queue = "..." } else { ... } } As mentioned, though, tags are file-order-dependent, which makes them not a very good solution, and really, they kind of obscure what you''re doing here, and they don''t maximize configuration normalization. I''d recommend writing a custom function that can turn the hostname into a queue, and then use the default node. You can use a one-liner in generate(), instead: $name = ch406a $site = generate("/usr/bin/ruby", "-e", "print ''$name''.sub(/[a-z]*$/, '''')") notify { "site is $site": } ==> notice: site is ch406 Note I don''t necessarily recommend these one-liners, but you get the idea. A server-side function, or a stand-alone script used with generate(), is a better option, if for no other reason than it''s clear what you''re doing and you don''t have to worry about quoting. Do this in the default node, then include the rsh class: node default { $queue = generate(...) # use $hostname include rsh } Then the rsh class just picks the file appropriate for a given queue. This still isn''t the best solution, since there is still the possibility of ordering quirks -- the rsh class must be included by the same scope that sets $queue (we''re working on this) -- but it should get you there. -- DOS is the _only_ operating system -- and I''m using that term loosely -- which [exhibits this behavior]. --Aeleen Frisch, "Essential System Administration" --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com