What Is an Environment?
An environment is an isolated copy of your Puppet code and data. Typical names are production, staging and development. A node belongs to exactly one environment at a time. Environments let you test a change on a few nodes before you give it to everyone.
Choosing an Agent's Environment
| Method | How |
|---|---|
| Default | production |
| On the node | environment = staging in puppet.conf or puppet config set environment staging |
| One time | puppet agent -t --environment feature_x |
| From the server (ENC) | The classifier returns environment: staging. Server wins over the agent setting, which is the safest and recommended approach when you use an ENC |
| From trusted data | Set via certificate extension pp_environment and read in your ENC or site.pp |
site.pp: The Classification Entry Point
Puppet reads manifests/site.pp for every node. Use it for node definitions and global settings.
default. Code outside node blocks applies to all nodes. Do not rely on matching multiple blocks.
Classification with Data (No Node Blocks)
A popular design is to avoid node blocks entirely and pick the role from a certificate extension or from Hiera.
External Node Classifier (ENC)
An ENC is a script or service that the server runs for every node. It returns YAML with the classes, parameters and environment for that node. It lets a CMDB, an inventory app or a UI decide classification.
| ENC output | Meaning |
|---|---|
classes | Map of class names. Parameters can be listed under each class |
parameters | Top-scope variables for the node ($datacenter) |
environment | Environment for this node, overrides the agent's setting |
Puppet Enterprise includes its own classifier in the console. The same ideas apply (node groups, classes, data, rules).
Which Method to Choose?
| Approach | Best when |
|---|---|
site.pp node blocks | Small setups, labs |
| Role from trusted fact | Cloud, automation, no per-node lists |
Hiera classes key | Data-driven teams that avoid node blocks |
| ENC or console | Large estates with a CMDB or UI-based management |
Code Promotion Workflow
Canary Rollouts
- Create a small group of canary nodes that use
productioncode first (or have their own branch) - Watch their reports in PuppetDB or the console for 30 to 60 minutes
- Then move the change to everyone
- For risky changes, set
noop => trueon those nodes only and review the planned changes
noop = true in the agent's puppet.conf, or to apply the noop metaparameter on individual resources: package { 'x': noop => true }.
Environment Caching
Puppet Server caches environment code for speed. With environment_timeout = unlimited, the cache is flushed by the deploy tool (r10k or Code Manager calls the environment-cache API). If code changes by hand and nothing seems to update, flush it:
Practice Tasks
- Create
stagingandproductionenvironments with different Hiera data and run an agent against each - Write a
site.ppwith an exact node, a regex node and a default node, and test which one matches withpuppet apply --certname - Write a small ENC script and configure the server to use it
- Compare compiled catalogs for two environments with
puppet catalog compile - Define your own promotion workflow on paper: branches, tests, canary and rollback
Conclusion
Environments isolate code and data. Classify nodes with roles from trusted facts, Hiera or an ENC, test changes on a branch environment with --noop, then promote through staging and canary nodes to production.

