The Problem
Imagine 200 servers. Some are web servers, some are databases, some are build machines. If you list classes directly in site.pp for each node, you get a huge file with copy-paste everywhere. The roles and profiles pattern solves this with simple layers.
The Layers
| Layer | Job | Rules |
|---|---|---|
| Component module | Manages one technology in a generic way (nginx, postgresql) | From the Forge or written by you. No company-specific choices |
| Profile | Configures one technology stack our way, using component modules | Contains logic and looks up data from Hiera. Each profile is one class |
| Role | Names a business function by including profiles | Only include profile::x lines. No logic and no parameters |
| Node | Gets exactly one role | include role::webserver in site.pp or an ENC |
Component Module (Generic)
These are the Forge modules or your own, such as puppet-nginx. They offer classes and defined types with parameters. You do not edit them.
Profile: Your Technology Stack
class { 'nginx': } with parameters, because it is the only place that declares it. Parameters come from the class parameters and from Hiera (profile::nginx::vhosts).
Role: The Business Function
Classification: Node Gets a Role
Often the role comes from a trusted fact so no node list is needed. A certificate extension pp_role (set at agent install time) or a custom fact decides the role.
Hiera Data for Profiles
Rules to Follow
| Rule | Reason |
|---|---|
| A node has one role | Keeps meaning clear. Variations become new roles or Hiera data |
| Roles only include profiles | No logic, no parameters, no resources |
| Profiles include or declare component modules | One place that decides how a technology is configured |
| Data lives in Hiera, not in profile code | Change values without changing code |
| Do not include a role from a profile | Layers go downward only |
Do not use class { 'x': } for one class in two profiles | Duplicate declaration. Use include and Hiera instead |
Name profiles by technology (profile::postgresql) | Not by environment or node |
Anti-Patterns
- Putting
if $hostname == 'web01'in profile code. Put the difference in Hiera - A role per node (
role::web01). That is just node-based classification again - Profiles that are huge. Split them (
profile::base::ssh) - Setting parameters of component modules from
site.pp - Using inheritance between profiles
- Many roles that differ by one profile. Use data to switch the behaviour instead
Full Mini Example
Practice Tasks
- Create
profile::base,profile::nginxandrole::webserverin a local site-modules directory - Classify two fake nodes with
site.ppand apply withpuppet apply --modulepath - Move the nginx port and vhosts into Hiera data and override per node
- Add
role::databaseand makesite.ppselect the role from a custom fact - Refactor a copy-pasted
site.ppinto roles and profiles
Conclusion
Use component modules for technologies, profiles to configure them your way with Hiera data, roles to name the business function, and give each node one role. This keeps classification simple and code reusable.

