Chef – 11–Knife Commands

knife node list

knife node show cnode1


Chef – 10– Knife Bootstrap a Node


#now we will bootstrap a node with knife

knife bootstrap –ssh-user ubuntu –sudo –ssh-identity-file .chef/resource.pem –run-list ‘recipe[learn_chef_apache2]’ –node-name cnode1

#we successfully bootstraped a node then we checked with curl and we saw the same result “HELLO WORLD” 🙂

Chef – 07– Cookbooks

#you can generate the cookbook with this command
chef generate cookbook learn_chef_apache2

#run the ‘tree’ command. if you dont have a tree package you can install with apt-get install tree

chef generate template learn_chef_apache2 index.html
#it will create a template file index.html.erb in templates folder

# then we must edit the default.rb recipe

sudo nano learn_chef_apache2/recipes/default.rb

package ‘apache2’

service ‘apache2’ do
action [ :enable, :start]

template ‘/var/www/html/index.html’ do
source ‘index.html.erb’

#then run the command
chef-client –local-mode –runlist ‘recipe[learn_chef_apache2]’

# change the erb file and re run the chef cookboks then run curl localhost you will see the changes

#you can upload your cookbook to chef server

knife upload cookbook learn_chef_apache2