Skip to main content

Chef notes

run cookbook locally
chef-client --local-mode recipes/default.rb

genrate cookbook 
chef generate cookbook cookbooks/apache

add a node in chef 
knife bootstrap -N --ssh-user root

show node details 
knife node show -l

find all attribute names

search all nodes
knife search 'platform:centos' knife search 'platform:centos' -a ipaddress knife search role 'role:apache' -a run_list knife search ":" -a recipes

add recipes to node 
knife node run_list add 'recipe[test]'

add another recipe from the cookbook
knife node run_list add 'recipe[test::test2]'

change recipe order (before)
knife node run_list add -b 'recipe[test::test2]'
knife node run_list add -a 'recipe[test::test2]'

remove all
knife node run_list remove 'recipe[test],recipe[test::test2]'

knife node run_list add 'recipe[test],recipe[test::test2]'

upload changes
knife cookbook upload recipe_name

create role
knife role create web

edit role
knife role edit web

add a role to a node
knife node run_list set "role[web]"

execute chef client from workstation
knife ssh "role:web" "chef-client" -x root -P passwd


  • list: knife cookbook site list
  • search: knife cookbook site search mysql
  • show: knife cookbook site show mysql
  • download: knife cookbook site download mysql
  • install: knife cookbook site install mysql


  • docker_plugin: chef exec gem install kitchen-docker
  • edit yaml: .kitchen.yml
  • setup env: kitchen converge
  • check test env: kitchen list
  • verify: kitchen verify

check syntax
ruby -c default.rb
foodcritic default.rb

Install chef server (after RPM):
chef-server-ctl reconfigure
chef-server-ctl user-create dave dave g 'password' --filename daveuser-rsa
chef-server-ctl org-create DaveChef 'Daves Chef Server' --association dave
chef-server-ctl org-create davechef 'Daves Chef Server' --association dave -filename davechef-validator.pem

Install web:
chef-server-ctl chef-manage
chef-server-ctl install chef-manage
chef-server-ctl reconfigure