Chef Tutorial
Learn Chef step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Chef? Learn what Chef is, why teams use configuration management, what idempotent and declarative mean, and how a Ruby stand-in lets you practice the core ideas here.
- Chef Vocabulary and Workflow Learn the core Chef words: resource, recipe, cookbook, node, run list, attribute and Chef Infra Client, and see how they fit in a typical workflow from code to node.
- Your First Chef Recipe Write and understand your first Chef recipe with package, file and service resources, learn the resource syntax, and run a Ruby stand-in that models resource order.
- Chef Workstation and Tools Tour the Chef toolbox: Chef Workstation, chef-cli, knife, Cookstyle, Test Kitchen and local mode, with real commands shown read-only and a runnable command-line stand-in.
- Ruby You Need for Chef Learn the small part of Ruby that Chef recipes use every day: strings and interpolation, arrays, hashes, blocks, conditionals and loops, with runnable examples.
Architecture and Setup
- Chef Architecture Understand how Chef is built: workstation, Chef Infra Server, nodes, the pull model, organizations, and how cookbooks and node data move between them.
- The Chef Client Run Follow a Chef Infra Client run step by step: Ohai, authentication, building the node object, compile and converge phases, and the classic compile-time versus run-time gotcha.
- Ohai and the Node Object Learn how Ohai collects facts about a machine, what the node object holds, which automatic attributes you use most, and how recipes branch on platform and memory.
- Chef Infra Server and Bootstrapping Learn how a node joins Chef: the Infra Server and organizations, knife bootstrap, client.rb, client keys, first-boot.json and run lists, with a runnable Ruby model.
Resources and Recipes
- Chef Resources and Actions Understand Chef resources deeply: types, name properties, properties, actions, default actions, providers, why resources are idempotent, and how to read the docs.
- package, service and file Resources Master the three most used Chef resources: package (install, version, remove), service (enable, start, restart) and file (content, owner, mode), including cookbook_file and template.
- directory, user, group and execute Learn more core Chef resources: directory with recursive creation, user and group management, execute for commands, plus link and cron, with runnable stand-ins.
- Guards and Idempotence in Chef Learn Chef guards: only_if, not_if, creates, guard_interpreter and Ruby block guards, how they keep execute resources idempotent, and how to avoid common guard mistakes.
- Chef Notifications and Subscribes Learn how Chef resources trigger each other: notifies and subscribes, delayed versus immediate and before timers, action :nothing, and the restart-on-config-change pattern.
- Ruby in Recipes - Loops, Conditions and ruby_block Use Ruby inside Chef recipes the right way: loops that create resources, platform helpers, data-driven recipes, ruby_block, lazy values and the compile-time trap.
Cookbooks and Attributes
- Chef Cookbook Structure Explore the layout of a Chef cookbook: metadata.rb, recipes, attributes, templates, files, libraries, resources, tests and Kitchen config, with a runnable layout checker.
- Chef Attributes and Precedence Learn Chef attributes: attribute files, default, force_default, normal, override and automatic levels, the 15-level precedence order, deep merging, and a runnable precedence model.
- Cookbook Metadata and Dependencies Manage cookbook dependencies in Chef: depends in metadata.rb, version constraints, include_recipe, Berkshelf and the Chef Supermarket, with a runnable constraint resolver.
- Writing Custom Resources in Chef Write your own Chef resources: files in resources/, property and action blocks, default actions, converge_if_changed, load_current_value, and a Ruby model of the pattern.
Templates and Data Bags
- Templates and ERB Basics Learn how the Chef template resource renders ERB files into configuration files, how idempotence works, and try a runnable Ruby stand-in for rendering.
- Template Variables, Helpers and Partials Go deeper with Chef templates: passing variables, conditionals and loops, helper methods, partial templates and keeping logic out of ERB, with runnable examples.
- Data Bags: Shared Data for Many Nodes Learn what Chef data bags are, how data bag items are stored as JSON, how recipes load and search them, and when to use them instead of attributes.
- Encrypted Data Bags and Secrets Learn how Chef encrypted data bags protect passwords and keys, how the secret key is shared, what the sensitive property does, and modern secrets alternatives.
Roles, Environments and Policyfiles
- Roles and Run Lists Learn how Chef roles bundle recipes and attributes, how run lists expand and run in order, the wrapper cookbook alternative, and expand a run list in Ruby.
- Environments and Cookbook Version Constraints Learn how Chef environments separate dev, staging and production, how cookbook version constraints such as ~> work, and test constraint matching in Ruby.
- Attribute Precedence with Roles and Environments Learn the 15 Chef attribute precedence levels, how roles and environments fit in, how hashes are deep merged, and how to debug where a value came from.
- Policyfiles and Dependency Locking Learn how Chef Policyfiles replace roles, environments and Berkshelf with one versioned, locked artifact, and build a dependency resolver and lock file in Ruby.
Testing with Test Kitchen
- Test Kitchen: Testing Cookbooks on Real Machines Learn Test Kitchen for Chef: kitchen.yml drivers, platforms and suites, the create, converge, verify and destroy lifecycle, and model the lifecycle in Ruby.
- ChefSpec: Fast Unit Tests for Recipes Learn ChefSpec for Chef recipes: how it converges without changing a machine, common matchers, stubbing, platform mocking, and write unit tests with a Ruby stand-in.
- InSpec and Cookstyle: Verify and Lint Learn InSpec controls and resources to verify servers, how Test Kitchen runs them, and how Cookstyle lints cookbooks, with a runnable Ruby stand-in of an InSpec-style DSL.
Scale and Operations
- Chef Infra Server, Knife and Search Learn what the Chef Infra Server stores, the essential knife commands for nodes, cookbooks, roles and data bags, and how search queries find nodes, with a Ruby model of search.
- The chef-client Run, Handlers and Reporting Understand each phase of a chef-client run, how the two-phase compile and converge model works, notifications, report handlers and run status, with a runnable Ruby model.
- Splay, Intervals and Scaling Chef Runs Learn how chef-client interval and splay prevent a thundering herd, how load grows with node count, ways to scale the Chef Server, and simulate splay in Ruby.
- Troubleshooting Chef Runs and Why-Run A practical guide to debugging Chef runs: reading errors, log levels, why-run mode, chef-shell, common failure patterns, and a runnable why-run model in Ruby.
Projects and Practice
- Project: A Complete Web Server Cookbook Build a complete Chef cookbook for a web server: metadata, attributes, template, recipe, notifications, ChefSpec and InSpec tests, plus a runnable Ruby simulation.
- Project: A Multi-Environment Fleet Combine roles, environments, data bags, search and Policyfile ideas in one project: manage dev, staging and production servers with a shared cookbook, in a Ruby model.
- Chef Practice Set and Interview Questions Practice what you learned about Chef templates, data bags, roles, environments, Policyfiles, testing and operations with exercises, runnable solutions and interview Q and A.