Chef Development
Install Chef-solo
- Install Ubuntu OS as a Virtual Machine on Virtual Box.
- Open terminal.
- Go to root terminal by ---->> sudo gnome-terminal.
- Write following commands ----->> cd ~
- Install Chef using curl ---->> curl -L https://www.opscode.com/chef/install.sh | bash.
- Message - "Thank you for installing Chef! ".
- Check Chef Version ------>> chef-solo -v
- Chef Installed.
First Chef cookbook
- Install and Configure Apache Web Server, MySQL, PHP. And Deploy our website on it.
- Set up a file structure before creating cookbook.
- File Structure repository provided by Opscode is "chef repository".
- Commands are as follows:
- wget http://github.com/opscode/chef-repo/tarball/master.
- tar -zxf master.
- mv chef-chef-repo* chef-repo
- rm master.
- Lets check inside of Chef-Repo folder.
- cd chef-repo/
- ls
- Lets call our cook book a "phpapp".
- Now we use knife to manage cookbook i.e. phpapp.
- Make Directory with .chef extension ----->> mkdir .chef
- echo "cookbook_path [ '/root/chef-repo/cookbooks' ]" > .chef/knife.rb
- Now create phpapp using Knife ------->> knife cookbook create phpapp
- If it wont work then HERE is a little TRICK.
- Run the following command and add a line into it.
- vi chef-repo/.chef/knife.rb
- ADD THESE LINES ------>> cookbook_path [ ' /root/chef-repo/cookbooks ' ]
- It will create phpapp folder in /root/var/chef/cookbooks/phpapp/
- Then we move that folder inside the /home/chef-repo/cookbooks/
- ----------->>sudo mv /var/chef/cookbooks/phpapp/ /home/anshul/chef-repo/cookbooks/.
- This will create our first app.
write our cookbook to install and configure Apache, MySQL and PHP
- Start with apache2
- root@anshul:~/chef-repo/cookbooks# knife cookbook site download apache2
- HERE is the terminal commands -
- root@anshul-VirtualBox:~/chef-repo/cookbooks/phpapp# cd ..
root@anshul-VirtualBox:~/chef-repo/cookbooks# knife cookbook site download apache2
Downloading apache2 from the cookbooks site at version 3.1.0 to /home/anshul/chef-repo/cookbooks/apache2-3.1.0.tar.gz
Cookbook saved: /home/anshul/chef-repo/cookbooks/apache2-3.1.0.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# tar zxf apache2*
root@anshul-VirtualBox:~/chef-repo/cookbooks# rm apache2*.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# knife cookbook site download apt
Downloading apt from the cookbooks site at version 2.7.0 to /home/anshul/chef-repo/cookbooks/apt-2.7.0.tar.gz
Cookbook saved: /home/anshul/chef-repo/cookbooks/apt-2.7.0.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# tar zxf apt*
root@anshul-VirtualBox:~/chef-repo/cookbooks#
root@anshul-VirtualBox:~/chef-repo/cookbooks# rm apt*.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# knife cookbook site download iptables
Downloading iptables from the cookbooks site at version 1.0.0 to /home/anshul/chef-repo/cookbooks/iptables-1.0.0.tar.gz
Cookbook saved: /home/anshul/chef-repo/cookbooks/iptables-1.0.0.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# tar zxf iptables*
root@anshul-VirtualBox:~/chef-repo/cookbooks# rm iptables*.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# knife cookbook site download logrotate
Downloading logrotate from the cookbooks site at version 1.9.1 to /home/anshul/chef-repo/cookbooks/logrotate-1.9.1.tar.gz
Cookbook saved: /home/anshul/chef-repo/cookbooks/logrotate-1.9.1.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# tar zxf logrotate*
root@anshul-VirtualBox:~/chef-repo/cookbooks# rm lograrate*.tar.gz
rm: cannot remove ‘lograrate*.tar.gz’: No such file or directory
root@anshul-VirtualBox:~/chef-repo/cookbooks# rm logrorate*.tar.gz
rm: cannot remove ‘logrorate*.tar.gz’: No such file or directory
root@anshul-VirtualBox:~/chef-repo/cookbooks# rm logrotate*.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# knife cookbook site download pacman
Downloading pacman from the cookbooks site at version 1.1.1 to /home/anshul/chef-repo/cookbooks/pacman-1.1.1.tar.gz
Cookbook saved: /home/anshul/chef-repo/cookbooks/pacman-1.1.1.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks# tar zxf pacman*
root@anshul-VirtualBox:~/chef-repo/cookbooks# rm pacman*.tar.gz
root@anshul-VirtualBox:~/chef-repo/cookbooks#