Puppet Agent: The client application that runs on managed nodes and applies configurations.
Puppet Master: The central server that compiles catalogs and serves them to agents.
Catalog: A document describing the desired state of a node.
Manifests: Files containing Puppet code that define resources and configurations.
Modules: Reusable collections of manifests, templates, and other files.
Resources: Represent individual components of a system (e.g., files, packages, services).
Browse / Puppet Cheatsheet
Puppet Cheatsheet
A comprehensive cheat sheet covering essential Puppet concepts, syntax, and commands for effective infrastructure management and automation in DevOps and Cloud environments.
Puppet Fundamentals
Core Concepts
|
Facts: Information about a node, such as its hostname, IP address, operating system, etc. Facts are automatically discovered by Facter. |
Classes: Reusable blocks of Puppet code that define a specific configuration. Classes are the primary means of organizing Puppet code. |
Puppet Workflow
|
Basic Syntax
Resource Declaration |
|
Variable Assignment |
|
Conditional Statements |
|
Puppet Resources
Common Resource Types
file: Manages files and directories. |
File Resource Attributes
|
Specifies whether the file should be present, absent, a directory, a link, etc. |
|
The path to the file. |
|
The content of the file. |
|
The source file to copy content from (used for templates). |
|
The owner of the file. |
|
The group of the file. |
|
The permissions of the file (e.g., ‘0644’). |
Package Resource Attributes
|
Specifies whether the package should be installed, absent, or a specific version. |
|
The name of the package. |
|
The package provider (e.g., yum, apt, gem). |
Puppet Modules & Classes
Module Structure
A Puppet module typically has the following directory structure:
|
Defining Classes
Basic Class Definition |
|
Class Parameters |
|
Including Classes
|
Simplest way to include a class. Can only be used once per class. |
|
Ensures that the class is applied before the current class. |
|
Similar to include, but allows classes to be declared multiple times. |
Advanced Puppet Features
Templates
Puppet uses Embedded Ruby (ERB) templates to generate dynamic configuration files. Templates are located in the Example (mytemplate.erb):
To use a template in a manifest:
|
Facts and Variables
Accessing Facts |
|
Custom Facts |
Custom facts can be created in Ruby or as executable scripts. They are stored in the |
Variables |
|
Hiera
Hiera is a key-value lookup tool for Puppet. It allows you to externalize data from your Puppet code. Example (hiera.yaml):
Example (common.yaml):
Using Hiera data in Puppet:
|