Skip to content

Latest commit

Β 

History

History
82 lines (58 loc) Β· 3.02 KB

File metadata and controls

82 lines (58 loc) Β· 3.02 KB

πŸ“ The Puppet Language Reference

"It's not programming, it's declaring your intentions to the universe. The universe just happens to be made of servers."


Overview

The Puppet language (also called the Puppet DSL) is a declarative, domain-specific language designed for one thing: describing the desired state of your infrastructure. You don't tell Puppet how to do something β€” you tell it what you want, and it figures out the rest.

If you're coming from shell scripting or Python, this requires a small shift in thinking. Instead of writing:

# Imperative (shell): HOW to do it
if ! rpm -q httpd; then
    yum install -y httpd
fi
systemctl enable httpd
systemctl start httpd

You write:

# Declarative (Puppet): WHAT you want
package { 'httpd':
  ensure => installed,
}

service { 'httpd':
  ensure => running,
  enable => true,
}

Same result, but the Puppet version is idempotent, cross-platform (mostly), and self-documenting. Let's dive in.


Table of Contents

Each topic has its own page with detailed explanations and copy-pasteable examples.

Language Basics

# Topic Description
1 Resources The fundamental building blocks β€” types, titles, and namevars
2 Resource Types Reference file, package, service, user, group, cron, exec β€” with examples
3 Variables & Data Types Variables, facts, scope, type system, and parameter validation
4 Strings, Arrays & Hashes String interpolation, heredocs, arrays, hashes, and nested access

Control Flow & Structure

# Topic Description
5 Conditionals if/elsif/else, case statements, and selectors
6 Classes Defining, declaring, and parameterizing classes
7 Defined Types Reusable resource templates β€” instantiate multiple times
8 Relationships & Ordering Arrow notation, metaparameters, and chaining
9 Iteration each, map, filter, and reduce

Advanced Topics

# Topic Description
10 Functions Built-in functions for strings, arrays, hashes, and lookups
11 Templates EPP (preferred) and ERB templates for dynamic file content
12 Node Definitions Assigning code to specific nodes in site.pp
13 Regular Expressions Ruby-style regex matching, capture groups, and case statements

Putting It Together

# Topic Description
14 Real-World Example A complete NTP module using everything you've learned

Next up: CLI Reference β†’

This document was created with the assistance of AI (Grok, xAI). All technical content has been reviewed and verified by human contributors.