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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s