The Install, Configure, Run Pattern
Most Puppet code for a software product follows three steps: install the package, write the configuration, start the service. These are the package, file and service resource types.
The package Resource
| Attribute | Values | Meaning |
|---|---|---|
ensure | installed (or present) | Install if missing, do not upgrade |
latest | Always upgrade to the newest version (use carefully in production) | |
absent, purged | Remove the package (purged also removes config on Debian) | |
'1.24.0-1' | Pin a specific version | |
provider | apt, dnf, yum, gem, pip3, windows, chocolatey | Which tool installs it |
install_options | array | Extra flags for the tool |
name | string | Real package name if different from the title |
Different package names per OS
ensure => installed, Puppet changes nothing once the package exists, which is the safest default. latest makes every run a possible upgrade, which can surprise you. Many teams pin versions or manage updates with a patch tool instead (see the Bolt lesson).
The service Resource
| Attribute | Values | Meaning |
|---|---|---|
ensure | running or stopped | Current state |
enable | true, false, mask | Start at boot |
hasrestart, hasstatus | true | Does the init script support these? (default is fine on systemd) |
restart, start, stop, status | command string | Custom commands when the default does not work |
provider | systemd, windows... | Normally detected automatically |
When a resource uses notify => Service['nginx'] and changes, the service is restarted (or runs your restart command). If the service is stopped, Puppet starts it.
The file Resource
| Attribute | Meaning |
|---|---|
ensure | file, directory, link, absent, or present |
path | The full path (usually the title) |
content | The exact text (string or from epp()) |
source | Copy from Puppet (puppet:///modules/mod/file) or another location. Do not use together with content |
target | Destination of a symbolic link |
owner, group | Name or ID |
mode | String like '0644' or symbolic 'u=rw,go=r'. Always quote it |
recurse | true to manage directory contents |
purge | Remove files that Puppet does not manage (needs recurse) |
force | Allow removing a directory |
backup | Where changed files are saved ('.puppet-bak' or a filebucket) |
replace | false means create the file but never overwrite it |
checksum | How to detect changes (sha256, mtime, ...) |
show_diff | Include the diff in the log (hide for secrets) |
Files, directories and links
require for these.
Manage a whole directory
purge deletes: With purge => true, every unmanaged file in that directory is removed. Test it in a lab first. Never use it on a directory such as /etc or /home.
Create only if missing
Where source files live
puppet:///modules/profile/nginx.conf means: module profile, file files/nginx.conf. The path after the module name is relative to the files directory. Files in files/ are served by the Puppet server to the agent.
A Complete Example: Nginx Web Server
Inspecting Resources on a Machine
Common Problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Package not found | Wrong name for the OS or repository not set up | Check with apt search or dnf search, add the repo first |
| Service starts then stops | Config error | journalctl -u name, validate config |
| File always changes | Content differs each run (timestamps) or mode quoted wrongly | Remove changing data, quote mode as a string |
Could not find declared class | Source path or module name wrong | Check files/ directory layout |
| Service not restarted | Missing notify | Add notify => Service[...] |
Practice Tasks
- Install
htop,treeandjqwith one package resource and confirm withpuppet resource package - Manage
/etc/motdwithcontent, then change the file by hand and run Puppet to see it restored - Create a directory
/opt/demowith two files and a symlink in/usr/local/bin - Write the nginx example above and prove that changing the template restarts nginx
- Use
replace => falsefor a file and verify that your manual edits stay
Conclusion
Use package to install, file to configure and service to run, and connect them with require and notify. Quote file modes, avoid purge where unsure, and use puppet resource to inspect the current state.

