Thursday, 3 July 2014

Chef solo: Chef Installation and create first cookbook

 Install curl for installing chef
           apt-get install curl*

Installing chef using curl
      curl -L https://www.opscode.com/chef/install.sh | bash
      You can choose the chef install link from according to your OS.
      http://www.getchef.com/chef/install/
 
Checking chef is installed or not or verifing the installation
        chef-solo -v

Now you need to get the file structure of chef in order to organise the various cookbooks
        wget http://github.com/opscode/chef-repo/tarball/master
        tar zxf master
        mv opscodee-chef-repo* chef-repo

Now to get to start writing cookbook for apache
        cd chef-repo
        mkdir .chef

We use knife cli tools to create cookbooks . First we need to tell knife where to fetch the cookbook
         echo "cookbook_path [  '/root/chef-repo/cookbooks'  ] "  >   .chef/knife.rb

Now we will create a phpapp cookbook
         knife cookbook create phpapp
         cd cookbooks

Now we download cookbook which acts a library for our cookbook
    Apache2
         knife cookbook site download apache2
         tar zxf  apache2*
 
    Apt - which ensure that chef-solo mkaes a apt-get update before we install any packages.
         knife cookbook site download apt
         tar zxf apt*
    Iptables

        knife cookbook site download iptables
        tar zxf iptables*
 
   Logrotate -
        knife cookbook site download logrotate
        tar zxf logrotate*
   Pacman
        knife cookbook site download pacman
        tar zxf pacman*

Now we configure these things
         cd phpapp/

Now we need to make changes in different configuration files
     open metadata.rb
     add line
     depends "apache2"

Open recipe/default.rb add lines
        include_recipe "apache2"
         apache_site "default" do
              enable true
         end

       cd ../..
    create a file solo.rb and add lines
    file_cache_path "/root/chef-solo"
    cookbook_path "/root/chef-repo/cookbooks"

Again create a file name web.json
    add lines
    {
         "run_list" :   ["recipe[apt]", "recipe[phpapp]"]
      }


Now finally execute below command to run the code
     chef-solo -c solo.rb -j web.json


 Note: using Ubuntu machine as OS in rackspace


No comments:

Post a Comment