Puppet Manifest Case Statement

Case statement for operating systems. This will install fuse-sshfs if the operating system is CentOS or RHEL, and sshfs if Ubuntu or Debian based. Because different Linux distributions name packages, paths and files differently, we can gracefully handle this within puppet on data gathered from facter on the servers. On a puppet agent (client) machine, run facter from the command line to see the data that can be queried.

case $operatingsystem {
'CentOS', 'RedHat': {
package { 'fuse-sshfs': ensure => installed }
'Ubuntu', 'Debian': {
package { 'sshfs': ensure => installed }

Puppet Manifest If

Say we are in the case statement above, and we have matched as a CentOS server, but we only want to ensure the service iptables is running if it's CentOS 6 because 7 runs firewalld by default. We can use an if statement to detect the release.

if $operatingsystemmajrelease == '6' {
service { 'iptables': ensure => running, enable => true, }
# Or we want only Ubuntu 14.04 LTS

if $lsbdistrelease == '14.04' {
# insert Ubuntu 14 specific packages, services and files here

Install Multiple Packages

If we have a list of packages to install, we could create a package definition for each, or create them as a list.

# Would work...
package { 'nagios-plugins-nrpe': ensure => installed }
package { 'nagios-plugins-disk': ensure => installed }
# ...

# this way is preferred, DRY up the code
package {
ensure => installed