Chef Cheat Sheet
Reference for Chef recipes, resources, cookbooks, and knife CLI commands used for infrastructure automation.
2 PagesAdvancedFeb 5, 2026
Basic Recipe
A recipe installing and configuring nginx.
ruby
package 'nginx' do action :installendtemplate '/etc/nginx/nginx.conf' do source 'nginx.conf.erb' owner 'root' group 'root' mode '0644' variables(port: node['nginx']['port']) notifies :restart, 'service[nginx]'endservice 'nginx' do action [:enable, :start]end
Core Concepts
Key Chef terminology and building blocks.
- cookbook- A packaged unit of recipes, attributes, templates, and files
- recipe- A Ruby DSL file declaring the desired state of resources
- resource- A statement describing a piece of system state (package, file, service)
- node- A managed machine running chef-client, with its own attributes
- run-list- Ordered list of recipes/roles applied to a node
- attributes- Configurable settings that parameterize recipes per node/environment
- data bag- Global JSON store for data shared across cookbooks (e.g. secrets, users)
Knife CLI
Common knife commands for managing the Chef ecosystem.
bash
knife cookbook create my_cookbook # Scaffold a cookbookknife cookbook upload my_cookbook # Upload to Chef Serverknife node list # List managed nodesknife node run_list add NODE 'recipe[my_cookbook]'knife ssh 'role:web' 'sudo chef-client' # Run chef-client remotelyknife bootstrap NODE_IP -x user -P pass --node-name web1
metadata.rb
Cookbook metadata file declaring name, version, dependencies.
ruby
name 'my_cookbook'maintainer 'DevOps Team'version '1.2.0'depends 'nginx', '~> 12.0'supports 'ubuntu'supports 'centos'
Pro Tip
Use Test Kitchen ('kitchen converge' / 'kitchen verify') to spin up isolated VMs or containers and validate recipes before uploading to your Chef Server.
Was this cheat sheet helpful?
Explore Topics
#Chef#ChefCheatSheet#DevOps#Advanced#BasicRecipe#CoreConcepts#KnifeCLI#MetadataRb#CommandLine#CheatSheet#SkillVeris