Puppet is an open-source configuration management tool that automates infrastructure provisioning, configuration, and management. It uses a declarative language to describe the desired state of your systems.
Puppet supports both agent-master and agentless (bolt) architectures, making it powerful for large-scale environments.
| Term | Description |
|---|---|
| Manifest | A file written in Puppet DSL (.pp) that describes desired system state. |
| Module | A collection of manifests, templates, files, etc., organized in structure. |
| Class | Reusable block of Puppet code. |
| Resource | Basic unit that describes something (like a package or service). |
| Facts | System information gathered by Facter. |
| Catalog | Compiled version of the manifests specific to a node. |
| Node | A client machine being managed. |
🟢 Beginner Commands (Click to Expand)
puppet --versionpuppet apply example.pppuppet parser validate example.pppuppet parser validate example.pp
puppet-lint example.ppfacter
facter ospuppet help
puppet help apply🟡 Intermediate Commands (Click to Expand)
puppet resource <type>
puppet resource user root
puppet resource service sshpuppet module generate yourname-modulenamepuppet module install puppetlabs-apachepuppet module listpuppet config print
puppet config print all🔴 Advanced Commands (Click to Expand)
puppet agent -t
puppet agent -t --debugpuppetserver ca list
puppetserver ca sign --certname node.example.com
puppetserver ca revoke --certname node.example.com
puppetserver ca clean --certname node.example.compuppet query 'inventory[certname] { facts.os.name = "Ubuntu" }'bolt command run "uptime" --targets localhost
bolt plan run myplanpuppet apply --noop file.pp
puppet apply --debug file.pp
puppet lookup varname
puppet describe <type>puppet config print <setting>
puppet facts show
puppet module search apache
puppet doc <module>
puppet resource --to_yaml# Install Puppet (Debian/Ubuntu)
sudo apt install puppet
# Check version
puppet --version# hello.pp
file { '/tmp/hello.txt':
ensure => present,
content => "Hello from Puppet!",
}Run it:
puppet apply hello.pp| Type | Example |
|---|---|
| file | Manage files, directories, symlinks |
| package | Install, remove software |
| service | Ensure a service is running/stopped |
| user | Manage system users |
# Install nginx and ensure it runs
package { 'nginx':
ensure => installed,
}
service { 'nginx':
ensure => running,
enable => true,
}$greeting = "Hello, World"
notice($greeting)if $osfamily == 'Debian' {
notice("Debian-based system")
} else {
notice("Other OS")
}View system facts:
facter
facter osUse in manifests:
if $facts['os']['family'] == 'RedHat' {
package { 'httpd': ensure => installed }
}class apache {
package { 'apache2': ensure => installed }
service { 'apache2': ensure => running }
}Include it:
include apachepuppet module generate yourname-apache
puppet module install puppetlabs-apacheStructure:
apache/
├── manifests/
│ └── init.pp
├── files/
├── templates/
Use:
class { 'apache': }File: templates/vhost.erb
<VirtualHost *:80>
ServerName <%= @servername %>
</VirtualHost>Manifest:
file { '/etc/httpd/conf.d/vhost.conf':
content => template('apache/vhost.erb'),
}| Mode | Usage |
|---|---|
| Apply | Local apply of manifests |
| Agent | Connects to master and applies catalog |
- Puppet Server: Central server managing infrastructure.
- Agent: Node that pulls configuration from the server.
# On agent
puppet agent -tSign certs:
puppetserver ca list
puppetserver ca sign --certname <agent-fqdn>Used to separate dev, staging, prod configs.
Directory structure:
/etc/puppetlabs/code/environments/
├── production/
│ └── manifests/
├── development/
Configure external data in YAML:
# hiera.yaml
version: 5
defaults:
datadir: data
data_hash: yaml_data
# data/common.yaml
apache::port: 80Access in Puppet:
$port = lookup('apache::port')Central storage for catalog, fact, and report data.
Query:
query_nodes(['=', 'catalog_environment', 'production'])bolt command run 'uptime' --targets localhost
bolt plan run myplanWrite plans in YAML or Puppet DSL.
| Command | Description |
|---|---|
puppet apply <file.pp> |
Apply a manifest locally |
puppet agent -t |
Trigger agent run |
puppet resource <type> <name> |
View current resource state |
puppet module install <name> |
Install a module |
puppet config print all |
Print all config settings |
puppet parser validate file.pp |
Validate syntax of manifest |
facter |
Show system facts |
puppet doc <module> |
Generate module documentation |
- 📘 Official Docs
- 📦 Forge Modules
- 🧪 Bolt (Task Runner)
- 📖 Puppet DSL Cheat Sheet
- 🧠 Learn Puppet Free Courses
