On 03/06/11 16:21, Douglas Garstang wrote:
I'd also like to see something, maybe in the best practices document on the Puppet Labs website indicating which is the correct way to handle specific operating ystem logic. Having multiple classes (ie a lot of classes) per module, means more files, which in my opinion, makes things confusing and it's never really clear which is the best way to break things up. When you have more than a few files, there's also a tendency to create subdirectories under manifests/, and have stuff like module::A::B.pp.... and when you start doing that, it becomes even more unclear how things should be arranged.

I guess it's up to the site and the Puppet admins on how to break up their classes. I'm not sure there's an all encompassing best practice as everyone's requirements will be different. For example if I was just managing CentOS and Red Hat systems, I might simply embed if/else logic in a single class and handle the differences in the OS there, as they are mostly the same and splitting off a separate class might be a waste of time.

If I was managing a site with Fedora, Ubuntu, Macs, etc, I'd definitely go down the "conditionally include classes and subclasses", mainly for management reasons, like a typo in "class somefile::ubuntu" doesn't affect "class somefile::redhat". Also the logging of resources indicates exactly which class::subclass::subsubclass a resource is declared in, so I know where to go hunting to make a change to it. In practice I'd make judgement calls about when to split a class into subclasses based on operating systems or to nest if/else statements in a class based on how complex the class was getting, and so I'd have a mixture of both.

All I was asking for was a way to conditional manage a resource based on the operating system. Something like:

file {

$operatingsystem ? {
  'centos' => {
    "/etc/somefile":
        source => ....
  },
  'default' => {}
}

Regarding your example above, that won't work, a Selector is a RHS operator, so can't be used like that. You'd need to either use a case statement or if/else block, from the docs:

|     if  $is_virtual  {
      service  {'ntpd':
        ensure  =>  stopped,
        enable  =>  false,
      }
    }
    else  {
      service  {  'ntpd':
        name        =>  'ntpd',
        ensure      =>  running,
        enable      =>  true,
        hasrestart  =>  true,
        require  =>  Package['ntp'],
      }
    }
|


--
Luke Bigum

Information Systems
luke.bi...@lmax.com | http://www.lmax.com
LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN



The information in this e-mail and any attachment is confidential and is 
intended only for the named recipient(s). The e-mail may not be disclosed or 
used by any person other than the addressee, nor may it be copied in any way. 
If you are not a named recipient please notify the sender immediately and 
delete any copies of this message. Any unauthorized copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden. Any view or 
opinions presented are solely those of the author and do not necessarily 
represent those of the company.

--
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to