Chef Command Reference
Essential Chef commands for managing cookbooks, recipes, and nodes.
Local Development Commands
# Apply a local recipe (recipe.rb in current directory)
chef-apply recipe.rb
# Run in local mode
chef-client --local-mode
# Check recipe syntax
chef exec ruby -c recipe.rb
# Generate a new cookbook
chef generate cookbook mycookbook
# Generate a new recipe inside a cookbook
chef generate recipe mycookbook myrecipe
# Run a specific recipe from a cookbook in local mode
chef-client -z -r "mycookbook::myrecipe"
Chef Client (Agent) Commands
# Run chef-client (pull from Chef Server)
chef-client
# Run with a specific runlist
chef-client -r "role[webserver]"
# Run with verbose output
chef-client -l debug
# Dry run (why-run mode)
chef-client --why-run
Knife Commands
# List nodes
knife node list
# Show node details
knife node show <node-name>
# Upload a cookbook
knife cookbook upload mycookbook
# List cookbooks
knife cookbook list
# Bootstrap a new node
knife bootstrap <ip> -U <user> -N <node-name> --sudo
# Run chef-client on a remote node
knife ssh 'name:<node>' 'sudo chef-client' -x ubuntu