Re: [Puppet Users] Why IF-ELSE not work?

jcbollinger
Thu, 14 Feb 2013 19:44:23 -0000

On Thursday, February 14, 2013 11:31:54 AM UTC-6, Евгений Верещагин
wrote:
>
> I want call diffrent manifest files for diffrent rules and systems. I
> think that write all rules in one file is not good idea :-)
>


No one suggested that you should put everything on one file.  Nevertheless,
you cannot "call" a manifest in the sense of a function.  Puppet DSL
is not
a scripting language, and manifests are not executable in any meaningful
sense.  You need to get your head around that (among other things) to
become proficient with Puppet.

Instead of thinking in terms of files, you should be working on modeling
your target systems via classes.  If you lay out your classes in the
recommended (and autoloader-supported) way, then the distinction will be
thin, as you will have only one class or definition per file.  The point,
however, is to harmonize your mental model with the way Puppet actually
works.

In your case, you might write site.pp like this:

manifests/site.pp
-------

# Prefer to avoid top-scope declarations other than node blocks,
# class definitions, and defined-type definitions
node default {
  # prefer to put logic in classes, keeping node blocks simple
  include ''site''
}

with a module site defined by:


modules/site/manifests/init.pp:
-------

class site {
  case $operatingsystem {
    redhat: { include ''site::redhat'' }
    centos: { include ''site::centos'' }
    windows: { include ''site::windows'' }
    default: { include ''site::default'' }
  }
}


modules/site/manifests/redhat.pp
-------

class site::redhat {
  # declarations for redhat systems
}


And similar classes site::centos, site::windows, and site::default as well,
each in its own file.


John