Random thoughts and technical bits

Basic Puppet

Earlier today I was helping a friend get started learning puppet. My favorite configuration management system. I figured some of the basics I shared might help others. His focus was on how to handle some very basic things in multiple operating systems. In these examples we will assume that I am working with two flavors of Linux RHEL and Suse.

Set ownership and file permissions:

file { "/etc/passwd":

owner => $operatingsystem ? {

redhat => "root",

suse => "root",

default => "root",

},

group => $operatingsystem ? {

redhat => "root",

suse => "wheel",

default => "root",

},

mode => $operatingsystem ? {

redhat => "644",

suse => "664",

default => "644",

},

} # end of file passwd

Simple process with an operating system switch. The variables you can trigger off in puppet can be found with the facter command. Once you understand your variables using case operators can be really powerful.

Push out a file with different sources:

file { "ntpdconfig":

name => "/etc/ntp.conf",

ensure => present,

replace => true,

owner => 'root',

group => 'root',

mode => '0644',

source => $operatingsystem ? {

redhat => "puppet:///files/redhat/ntp.conf",

suse => "puppet:///files/suse/ntp.conf",

default => "puppet:///files/redhat/ntp.conf",

};

}

Push out the file with different local sources by OS and replace the file if already present.

One of the things I love about puppet is the ability to to service checks. For example ensure that httpd is running and set to start at boot time. Sometimes the ability to check for the running service requires a custom setting which you can do with the following:

service { tivoli:

name => "startscript",

enable => true,

status => "/bin/ps -ef | /bin/grep startscript_process_name",

ensure => running,

}

In this case we can use the ps command to check for the process as running.

From time to time you need to push out a file and execute if something changes:

About Author

Joseph Griffiths is a virtualization focused solutions architect who works with complex cloud based solutions. He currently holds many IT certifications including VMware VCDX-DCV and VCDX-CMA #143. This blog represents his random technical notes and thoughts. The thoughts expressed here do not reflect Joseph’s current employer in anyway. You can follow Joseph on Twitter @Gortees