How to Use This Lesson
Read each question, answer it out loud in your own words, then compare with the model answer. Interviewers want clear thinking and a small example, not memorised text.
Section 1: Basics
1. What is Puppet?
Puppet is a configuration management tool. You describe the desired state of servers (packages, files, services, users) in code, and Puppet makes each server match that state and keeps it that way. It runs on Linux, Windows and other systems.
2. What does 'declarative' mean?
You describe what you want (package { 'nginx': ensure => installed }), not how to do it. Puppet decides the steps for each OS. This is different from a shell script, which lists commands.
3. What is idempotence?
Running the same code many times gives the same result, and changes nothing once the system is already correct. A second Puppet run should report zero changes. Example: if nginx is installed, ensure => installed does nothing.
4. Explain the Puppet architecture.
- Puppet Server holds code, Hiera data and the Certificate Authority
- Agent on each node sends facts and applies the catalog
- Facter collects facts. PuppetDB optionally stores facts, catalogs and reports
- Communication is HTTPS on port 8140 with certificates
5. What are the steps of an agent run?
- Agent runs Facter and sends facts to the server
- Server compiles a catalog from code, Hiera and facts
- Server sends the catalog
- Agent applies it (changes what is different)
- Agent sends a report to the server
6. What is a catalog?
A catalog is the compiled list of resources and their relationships for one specific node. It contains no logic anymore, only the final resources. Compiling happens on the server.
7. What are facts?
Facts are information about the node collected by Facter: OS, IP, memory, hostname and more. They are available in code as $facts['os']['family']. You can add custom facts.
8. What is a resource?
The basic unit of Puppet code. A resource has a type, a title and attributes: file { '/etc/motd': ensure => file, content => 'hi' }.
9. Puppet pull model vs push model?
The Puppet agent pulls its catalog from the server on a schedule (every 30 minutes by default). This helps with scale and drift correction. Tools like Ansible mostly push from a control machine when you run them. Puppet Bolt can also push.
10. How is Puppet different from Ansible and Chef?
| Puppet | Ansible | Chef | |
|---|---|---|---|
| Model | Pull with agent (also Bolt push) | Push, agentless (SSH) | Pull with agent (also push) |
| Language | Puppet DSL (declarative) | YAML playbooks (procedural flavour) | Ruby DSL |
| State handling | Continuous drift correction | On demand, when you run it | Continuous |
| Strength | Large fleets, compliance, data separation | Quick start, orchestration | Flexible Ruby code |
Section 2: Language and Code
11. What are the main resource types?
package, service, file, user, group, exec, cron, mount, host, ssh_authorized_key. The core pattern is package, file, service.
12. What is the difference between include and class {}?
include declares a class and can be repeated safely. Parameters come from Hiera. class { 'x': param => ... } is a resource-like declaration that sets parameters but can be used only once, and fails with a duplicate declaration if the class was already included. Prefer include with Hiera.
13. Class vs defined type?
A class is a singleton: it exists once per node. A defined type can be declared many times with different titles (for example virtual hosts or users).
14. How do you control the order of resources?
With relationships: require, before, notify, subscribe, and chaining arrows -> and ~>. notify also sends a refresh (restart a service) when the notifier changes. Puppet builds a dependency graph. Without relationships the order is not guaranteed.
15. What is notify => Service['nginx'] doing?
It makes the service apply after the resource, and when the resource changes (for example a config file), the service is restarted or reloaded. If nothing changes, no restart.
16. How do you write a condition in Puppet?
17. How do you loop in Puppet?
There is no for keyword. Use iteration functions with lambdas: each, map, filter, reduce.
18. What are the data types in Puppet?
String, Integer, Float, Boolean, Array, Hash, Undef, Regexp, Sensitive, Optional, Variant, Enum and more. Types are used to validate class parameters.
19. Can you change a variable after assigning it?
No. Variables are single assignment within a scope.
20. What is exec and when should you avoid it?
exec runs a command. It is not idempotent by default, so avoid it when a resource type exists. If you must use it, add creates, unless, onlyif or refreshonly.
21. What are templates?
Templates generate files from data. EPP (Puppet language, parameters) and ERB (Ruby). Use epp('module/file.epp', {...}) inside content.
22. What is validate_cmd?
An attribute on file that tests a temporary copy of the new file with a command before it replaces the real one. Used for sudoers, sshd and nginx configs.
Section 3: Modules and Hiera
23. What is a module?
A directory with a standard layout (manifests, files, templates, lib, data, metadata.json) that bundles code for one purpose. Class names map to file paths.
24. What is Puppet Forge?
A public site to find and share modules. You list modules in a Puppetfile with versions and deploy them with r10k or Code Manager.
25. What is Hiera?
A key-value lookup system that separates data from code. A hierarchy of YAML files (node, role, OS, common) decides the value. Class parameters are automatically looked up as class::param.
26. What are Hiera merge strategies?
first (default), unique (merge arrays), hash (merge top keys), deep (merge nested hashes). They can be set in lookup_options or the lookup() call.
27. What is the roles and profiles pattern?
Component modules manage technologies, profiles configure a technology stack with your data, roles describe the business function by including profiles, and each node has one role.
28. What is an environment?
An isolated set of code and data (production, staging, branches). Nodes belong to one environment. With r10k each Git branch becomes an environment.
Section 4: Practical Operations
29. How do you test a change safely?
Lint and unit tests in CI, then deploy to a branch environment and run puppet agent -t --noop --environment mybranch on a test node, then staging, canary nodes, then production.
30. What does puppet agent -t do?
Runs the agent once, in the foreground, with verbose output. Exit code 2 means changes were applied, 0 no changes, 4 failures.
31. What is --noop?
Dry run. Shows what would change, without changing anything.
32. How do you add a new node?
Install the agent, point it to the server, run puppet agent -t, which creates a certificate request. Sign it with puppetserver ca sign (or autosign with a policy). The node then receives its catalog.
33. How do you remove a node?
puppetserver ca clean --certname NAME and deactivate it in PuppetDB. Then delete the machine.
34. How often does the agent run?
Every 30 minutes by default (runinterval), with optional splay to spread the load.
Quick Coding Round: Write This From Memory
Conclusion
Know the architecture, the agent run, idempotence, the three core resources, classes versus defined types, relationships, Hiera and roles and profiles. Practise explaining each with a short example.

