Master Puppet: Principles, Workflow, Installation, and Resource Management
This comprehensive guide explains Puppet's core concepts, workflow, installation steps, resource management, language syntax, class/module structure, and provides a practical LNMP deployment example for automating Linux system configuration.
1. Puppet Basics
Puppet is an open‑source configuration‑management tool licensed under GPLv2+, written in Ruby. It can run in client‑server mode or standalone, providing administrators with fast, automated system management.
2. Puppet Workflow
1. The puppet client requests authentication from the puppet master, optionally using a signed certificate.
2. The master validates the client.
3. The client runs Facter to gather facts (hostname, memory, IP, etc.) and sends them over SSL.
4. The master matches the node to a manifest, parses it, performs syntax checks, and compiles a catalog (intermediate “pseudo‑code”) which is sent back to the client.
5. The client receives the catalog and applies it.
6. If a file resource is needed, the client requests it from the fileserver.
7. If reporting is configured, the client sends the execution result to the server.
8. The server logs the result and forwards it to the reporting system.3. Installing Puppet
1. Install the version that comes with the OS via yum.
yum install puppet -y2. Install the latest version.
sudo rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm2.1 Install puppet‑server.
sudo puppet resource package puppet-server ensure=latest2.2 Install the agent.
sudo puppet resource package puppet ensure=latest4. Puppet Resource Management
Resources are the smallest units that Puppet manages.
puppet describe -l # list all resource types
puppet describe -s <resource_name> # show a summary
puppet describe <resource_name> # show detailed usage
# Example resource definition:
resource_name { 'title':
attribute1 => 'value',
attribute2 => 'value',
}Common resource types: file, filebucket, host, group, package, service, exec, cron, notify, etc.
Public attributes:
before => specify a resource that must run before this one
require => specify a resource that must run after this one
notify => actively notify other resources of state changes
subscribe=> passively receive notifications when a dependent resource changes
# Relationship operators:
-> # ordering
~> # notification5. Puppet Language
Variables
$webserver = "httpd"
package { "httpd":
ensure => "present",
name => $webserver,
}Data types
String, Boolean, Integer, Float, Array (e.g., $array = ['httpd','mysql','php']), Hash, undefOperators
Comparison: ==, !=, <, >, <=, >=, =~, !~, in
Boolean: and, or, !
Arithmetic: +, -, *, /, <<, >>Conditional statements
if ... elsif ... else
case
selector
# Example:
if $osfamily == 'CentOS' { notice('welcome to CentOS') }
elsif $osfamily == 'RedHat' { notice('Welcome to RedHat') }
else { notice('Welcome to ET') }6. Classes and Modules
Classes group related code and must be declared before use.
class class_name [inherits] [base_class] {
# Puppet code
}
# Example module structure:
module_name/
manifests/
init.pp # declares the main class
*.pp
files/
templates/
lib/
tests/
spec/Inheritance and overriding are supported.
# inheritance of resource attributes, overriding, and appending (=>, +>)7. Example: Deploying LNMP with Puppet
Assume puppet‑server is already installed.
# Add host entries
cat >> /etc/hosts <<EOF
192.168.198.139 puppet-server
192.168.198.160 puppet-client
EOFCreate module directory and manifests
mkdir -p /etc/puppet/modules/lnmp/{manifests,files,templates,tests}
# init.pp
class lnmp {
include lnmp::nginx
include lnmp::mysql
include lnmp::php
}
# nginx.pp, php.pp, mysql.pp definitions (packages, files, services)
# site.pp
node 'puppet-client' { include lnmp }Copy configuration files
cp /root/files/{nginx.conf,www.conf,my.cnf} /etc/puppet/modules/lnmp/files/Start puppet services
# On the master
puppet master --verbose --no-daemonize
# On the client
puppet agent --server puppet-server --verbose --no-daemonize
# Sign the certificate on the master
puppet cert sign puppet-client8. Summary
This guide provides a concise reference for using Puppet to automate Linux system configuration, covering fundamentals, workflow, installation, resource handling, language features, class/module structure, and a practical LNMP deployment example.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
