Skip to main content

Chef notes

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 192.168.2.153 -N node-chef.myhypervisor.ca --ssh-user root

show node details 
knife node show -l node-chef.myhypervisor.ca

find all attribute names
ohai

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 fqdn.server.com 'recipe[test]'

add another recipe from the cookbook
knife node run_list add fqdn.server.com 'recipe[test::test2]'

change recipe order (before)
knife node run_list add fqdn.server.com -b 'recipe[test::test2]'
(after)
knife node run_list add fqdn.server.com -a 'recipe[test::test2]'

remove all
knife node run_list remove fqdn.server.com 'recipe[test],recipe[test::test2]'

add
knife node run_list add fqdn.server.com '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 fqdn.domain.com "role[web]"

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

supermarket

  • 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

    testing

    • 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 livegrenier@gmail.com '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