Skip to content

Chef Concepts

Chef models infrastructure through Ruby-based configuration code.

Core Concepts

  • Cookbook: the top-level unit of reuse.
  • Recipe: a file that declares configuration logic.
  • Resource: a building block such as package, service, template, or remote_file.
  • Attribute: a value used to parameterize recipes.
  • Node: the machine that Chef converges.
  • Run list: the ordered set of recipes applied to a node.
  • Knife: the command-line tool used to interact with Chef infrastructure.

How Chef Works

Chef converges a node toward the desired state. It repeatedly checks resources and only performs actions when the current state does not match the declared state.

Example Resource Pattern

package 'nginx' do
  action :install
end

service 'nginx' do
  action [:enable, :start]
end

Common Resource Types

  • package
  • service
  • template
  • file
  • directory
  • remote_file

Practical Notes

  • Use cookbooks as the unit of reuse.
  • Keep recipes small and deterministic.
  • Model configuration changes as resources instead of shell scripts where possible.