Skip to content

Puppetizing EL6 & EL7

One of the tricks in starting to deploy EL7 (Redhat Enterprise 7/RHEL7/CentOS 7) is that much of it is the same as EL6 but there are enough differences that base puppet classes need to be case’ed for the variations between them.  Making this more difficult is that the EPEL version of puppet supports $operatingsystemmajrelease on EL7 but not on EL6, so a class that works on both is tricky.  This will improve when the EPEL6 version of puppet gets updated, but for now, here are some workarounds:

In site.pp:

$os_major_version = $operatingsystemmajrelease ? {
  undef    => $lsbmajdistrelease,
  default  => $operatingsystemmajrelease,
}

And then in classes, for example:

  case $operatingsystem {
    centos, redhat: {

      case $os_major_version {
        7 : {
          package { "nmap-ncat" :
            ensure => installed
          } 
          package { "whois" :
            ensure => installed
          }
        }
        default : {
          package { "nc" :
            ensure => installed
          } 
          package { "jwhois" :
            ensure => installed
          }
        }
      }  
    } default : {
      package { "nc" :
        ensure => installed
      }
      package { "jwhois" :
        ensure => installed
      }
    }
  }

or:

      case $operatingsystem {
        centos, redhat: {

          if $os_major_version >= 7 {

            file { "/etc/default/grub" :
            ...

 

etc.   Making it even trickier is that the puppet ‘case’ operator can handle ‘undef’ and not throw a runtime error, but ‘>=’ cannot, so you can get lucky in some cases but have to work for it in others.  This, of course, means you should be testing your conditionals on each OS/release you support whenever you make changes as different runtime code paths will be exercised based on which way your code branches.  As far as I can see, there’s not a pre-runtime way to validate the code branches (that would be a nice future enhancement to puppet).

It’s worth the effort to make your classes handle multiple OS’s/versions – don’t give in to the temptation to copy a class to a ‘class-el7’ class or you’ll just have to maintain multiple copies forever, and that’s what we’re trying to get away from!