Roles & profiles

The standard design pattern.

Advanced12 min · lesson 10 of 12

Roles and profiles is the near-universal design pattern for organizing a Puppet codebase, and it exists because ad-hoc class assignment becomes unmaintainable. A profile is a wrapper class that configures one technology stack the way your organization wants it (profile::nginx pulls in the nginx module and sets your standards). A role composes profiles into a machine type (role::web includes profile::base + profile::nginx + profile::app). Each node is assigned exactly one role.

The layers
1component modules
nginx, apache, mysql…
2profiles
your opinionated wrappers
3roles
compose profiles into a type
4node
gets exactly one role
Modules are generic; profiles encode your standards; roles are business machine types; a node is one role.
roles/profiles
# profile: your opinionated use of a component module
class profile::nginx {
class { 'nginx': workers => 4 }
include profile::firewall::web
}
# role: compose profiles into a machine type
class role::web {
include profile::base
include profile::nginx
include profile::app
}
# node gets exactly one role (via Hiera or node definition)
# role: 'role::web'

Why the discipline pays off

The rules are strict on purpose: roles only include profiles (no resources), profiles are the only place that declares component classes with parameters and does Hiera lookups, and nodes get one role. This keeps the codebase navigable at scale — you always know where a decision lives — and makes machine types self-documenting. It is the single most important structural convention in real Puppet.

Keep resources out of roles, tech-config out of nodes
The pattern breaks down when people put resources directly in roles or configure technology in node definitions. Hold the line: roles compose profiles only, profiles own the technology configuration and Hiera lookups, and node data assigns a role and supplies data — nothing else. The discipline is the value; a “just this once” resource in a role is how the codebase slides back into unmaintainable.