My First CHEF Cookbook !

[The cookbook works only for debian based OS]

Login To Chef Workstation:

ssh -i key.pem ubuntu@chef-workstation

Chef Workstation, @chef-repo directory
Creating My Apache Cookbook

#knife cookbook create myapache
#vim cookbooks/myapache/recipes/default.rb

package "apache2"  do
        action :install

#To delete default VirtualHost
cookbook_file "/etc/apache2/sites-enabled/000-default" do
  action :delete

template "/etc/apache2/sites-enabled/default" do
        source "default.erb"
        mode "0644"

#To delete default index.html
cookbook_file "/var/www/index.html" do
  action :delete

cookbook_file "/var/www/index.html" do
  action :create

service "apache2" do
        action [:enable,:start,:reload]

Back To Terminal

#echo "This is myapache cookbook" > cookbooks/myapache/files/default/index.html
#vim cookbooks/myapache/templates/default/default.erb
<VirtualHost *:80>
DocumentRoot /var/www/

Back to Terminal, good to practice to update the cookbook version

#vim cookbooks/myapache/metadata.rb
version '0.1.1'

Upload the Cookbook to Chef-Server:

#knife cookbook upload myapache

Go To Chef Manage Console to 

  • Create a New Role called testrole2
  • Place the myapache cookbook in RunList of testrole2

Starting a new node to try out!

#knife ec2 server create -r "role[testrole2]" -I ami-8e987ef9 --flavor t1.micro -G unni-test-sg -x ubuntu -N MyChefPOC --region eu-west-1 -i /pathtosshkeyofNode.pem

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s