[Puppet Users] Re: split config by $lsbdistid

Mike Renfro
Tue, 07 Oct 2008 13:41:41 -0000

Vincent Louviaux wrote:

> Is it possible to split config files by distributions ?
>
> the goal is to define the same class but different by os distribution
> and not always define a case in all config files like
>
> class ntp {
> case "$lsbdistid $lsbdistcodename" {
>   "Ubuntu hardy":   {
> ..
>
>
> So I would like something like :
> import "classes/$lsbdistid/$lsbdistcodename/*.pp"

Three things: first, I *think* the import lines would end up being
evaluated on the puppetmaster, and wouldn''t use the clients''
facts.
Second, I''m not sure you''d save any effort, and would be
working against
the usual practice of "the files, templates, and manifests in my ntp
module tree are all I need to manage ntp on all the OSes I have to worry
about".

Third, you might be able to rework your case statements into selectors
and reduce the amount of repeated code that may be one cause for your
concerns (not knowing what''s in your current case statements,
it''s hard
to say for sure). Here''s an alternative that would work out pretty
compactly:

   file { ntpconf:
     path   => "/etc/ntp.conf",
     source => $operatingsystem ? {
         "Debian"  =>
"puppet:///ntp/ntp.conf.${lsbdistid}-${lsbdistcodename}",
         "Solaris" => "puppet:///ntp/ntp.conf.Solaris"
     },
     owner  => "root",
     group  => "root",
     mode   => 644,
   }

Recent versions of facter on Ubuntu may return "Ubuntu" for the
operatingsystem fact instead of "Debian".

--
Mike Renfro  / R&D Engineer, Center for Manufacturing Research,
931 372-3601 / Tennessee Technological University -- renfro@tntech.edu