Simpler Puppet Manifests – Resource Defaults and Manifest Ordering

Tips to make your Puppet manifests shorter and easier to read.
Resource defaults: If I say ‘package’, of course I want it installed. Services are usually running and enabled at boot.
Manifest ordering: Top-down, so I don’t have to ‘require’ the package in every other resource.

Puppet is the configuration management system used by Google (desktops and laptops), Wikipedia (servers) and US Gov (security baseline).

Top-Down Manifest Ordering

Look mom, no require! With ‘ordering=manifest’, manifests are read top down. Put your ‘package’ on top, and other resources don’t have to ‘require’ it.

$ sudoedit /etc/puppet.conf
[main]
ordering = manifest
# ...

Resource Defaults

A capitalized resource name by itself (e.g. ‘File’) means defaults.
If I say “package”, of course I want it installed. If I say ‘service’, I want it running and started at boot. And most files are root:root -rw-r–r–.

File { owner => '0', group => '0', mode => '0644', }
Package { ensure => 'installed', allowcdrom => true, }
Service { ensure => 'running', enable => true, }

I think I could put this on top of most manifests.

Example Module

Consider this simple Apache module that replaces the default web page and enables user homepages (example.com/~tero).
Notice how manifest ordering lets us leave out all requires. First run is still complete and error free.
Resource defaults (File, Package, Service) save a lot of lines. These settings are quite generic.

class apache {
	File { owner => '0', group => '0', mode => '0644', }
	Package { ensure => 'installed', allowcdrom => true, }
	Service { ensure => 'running', enable => true, }
	package { 'apache2':}
	file { '/var/www/html/index.html':
		content => 'See you at TeroKarvinen.com',
	}
	file { '/etc/apache2/mods-enabled/userdir.conf':
		ensure => 'link',
		target => '../mods-available/userdir.conf',
		notify => Service['apache2'],
	}
	file { '/etc/apache2/mods-enabled/userdir.load':
		ensure => 'link',
		target => '../mods-available/userdir.load',
		notify => Service['apache2'],
	}
	service { 'apache2': }
}

Adminstrivia

Tested on Ubuntu 16.04.3 LTS amd64 live USB, Puppet 3.8.5. Updated with an image and corrected typos.

Posted in Uncategorized | Tagged , , , , , | 1 Comment

One Response to Simpler Puppet Manifests – Resource Defaults and Manifest Ordering