site.pp

The site.pp is one of the oldest files found on a modern Puppet Master. The original intention of site.pp was to classify nodes, assigning classes and resources to a node to create a catalog. It accepts both regex and string match names, and, if used to place code and resources directly on a system, it would contain code such as the following:

node 'application.company.com' { include role::application }

Today, most users no longer store classifications in site.pp. Classification is handled by an external node classifier (ENC), such as the Puppet Enterprise Console. Hiera has also become a common method of classification, in lieu of an ENC. Any code that is not contained to a node in site.pp is applied to all nodes in the Puppet environment. The following code, placed outside of a node specification, searches all levels of a node's Hiera hierarchy for unique classes in an array named classes, removes anything contained in arrays named class_exclusions, and then applies them to each node. This allows Hiera to act as the classifier for Puppet nodes.

The following code enables Hiera as a classification strategy, when placed in site.pp:

#This section ensures that anything listed in Hiera under classes can be used as classification

$classes = lookup('classes', Array[String], 'unique')
$exclusions = lookup('class_exclusions', Array[String], 'unique')
$classification = $classes - $exclusions

$classification.include

If we had a server named snowflake.ourcompany.com, and the following was contained in our Hiera hierarchy, we would include role::ourapp and profile::partners::baseline, but exclude profile::baseline, even though it was listed as a class in common.yaml. This ensures that profile::baseline is applied everywhere in the infrastructure, except for where it is explicitly excluded:

# common.yaml
---
classes:
- profile::baseline

We can also use our above class exclusions to remove baseline from a particular node:

# nodes/snowflake.ourcompany.com.yaml
---
classes:
- profile::partners::baseline
- role::ourapp
class_exclusions:
- profile::baseline

site.pp also allows us to set some sane defaults to our Puppet code, across our entire environment. In the following example, any Windows machine will use the package provider Chocolatey, by default. Chocolatey is a free and open source solution to a Yum-like package manager on Windows. If you haven't tried it yet in your Windows environment, it is a significant improvement on installing directly from .msi or .exe:

# Set Default Package Provider to Chocolatey on Windows

if $::kernel = 'windows' {
Package {
provider => 'chocolatey'
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.137.213