As we know Chef is a system and cloud infrastructure automation framework that makes it easy to deploy servers and applications to any physical, virtual, or cloud location, no matter the size of the infrastructure. Cookbooks (and recipes) are used to tell the chef-client how each node in your organization should be configured. The chef-client (which is installed on every node) does the actual configuration.
VirtualBox is a cross-platform virtualization application. It allows us to install multiple guest hosts on a single physical host. So, for example, you can run Windows and Linux on your Mac, run Windows Server 2008 on your Linux server, run Linux on your Windows PC, and so on, all alongside your existing applications. You can install and run as many virtual machines as you like — the only practical limits are disk space and memory.
Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.
Purpose of the Article:
In this article we will learn how to Install Virtual Box, Vagrant and how to configure the Windows desktop as a Chef development machine
We will discuss about how to develop Chef cookbook, recipes, roles and test those on the Virtual Machines created using Oracle Virtualbox and Vagrant.
I will use my Windows desktop as the Chef development machine and I will provisioning the Chef recipes or Roles to the Virtual Machine to test and verify. We will develop a cookbook with set of recipes to install and Configure a LAMP environment to run a WordPress on that box.
Prerequisites:
- Windows Machine at least with 8 GB Ram and i3 Processor.
- Chef Development Kit for windows : Download URL
- Oracle Virtual Box : Download URL
- Vagrant : Download URL
- GIT : Download URL
- Chef Repo : Download URL
Installation Steps:
Chef Development Kit:
Download the Chef Development Kit for the given URL. Double Click on the Downloaded msi file and then Click on Run on the opened Dilog box.
Accept the License Agreement and Click on Next
Click on Next
Click on Install
It will take some time to complete the installation process. Click on Finish to complete.
VirtualBox:
Download the Oracle VirtualBox for the given URL. Double Click on the Downloaded exe file and then Click on Run on the opened Dilog box.
Then Click on Next >
It will take some time to complete the installation.
Vagrant:
Download the Vagrant for the given URL. Double Click on the Downloaded msi file and then Click on Run on the opened Dilog box.
Accept the License Agreement and Click on Next
Click on Install
It will take some time to complete the Setup. Click on the Finish button to Finish the Installation wizard.
After Installing Vagrant you need to install two Vagrant Plugins in your system. Issue to the below commands to install them. You can use Windows CMD or GIT bash to issue these commands.
$ vagrant plugin install vagrant-berkshelf --plugin-version 2.0.1 $ vagrant plugin install vagrant-omnibus
When you completed all the installations now use chef verify
Tapas@LINUXFUNDA /d $ chef verify Running verification for component 'berkshelf' Running verification for component 'test-kitchen' Running verification for component 'chef-client' Running verification for component 'chef-dk' Running verification for component 'chefspec' .................................................................................. --------------------------------------------- Verification of component 'chefspec' succeeded. Verification of component 'chef-client' succeeded. Verification of component 'berkshelf' succeeded. Verification of component 'test-kitchen' succeeded. Verification of component 'chef-dk' succeeded. Tapas@LINUXFUNDA /d
Download Chef Repository and Configure Knife:
Download Chef repository from the given URL and extract it to any destination. I have extracted it to my D:/ drive. After extraction you will find the folder named as “opscode-chef-repo-f9d4b0c”. Rename it as “Chef-Repo”. If you look inside the directory then you can see the following:
Tapas@LINUXFUNDA /d/Chef-Repo $ ls -l total 10 -rw-r--r-- 1 Tapas Administ 10850 Sep 27 2013 LICENSE -rw-r--r-- 1 Tapas Administ 3510 Sep 27 2013 README.md -rw-r--r-- 1 Tapas Administ 2169 Sep 27 2013 Rakefile drwxr-xr-x 1 Tapas Administ 0 Nov 28 07:23 certificates -rw-r--r-- 1 Tapas Administ 156 Sep 27 2013 chefignore drwxr-xr-x 1 Tapas Administ 0 Nov 28 07:23 config drwxr-xr-x 1 Tapas Administ 0 Nov 28 07:23 cookbooks drwxr-xr-x 1 Tapas Administ 0 Nov 28 07:23 data_bags drwxr-xr-x 1 Tapas Administ 0 Nov 28 07:23 environments drwxr-xr-x 1 Tapas Administ 0 Nov 28 07:23 roles Tapas@LINUXFUNDA /d/Chef-Repo $
I am using GIT bash as it is allowing me to issue some basic Linux commands on Windows host. Description about some useful directories.
- cookbooks
- The cookbooks/ directory is used to store the cookbooks that are used by the chef-client when configuring the various systems in the organization. This directory contains the cookbooks that are used to configure systems in the infrastructure. Each cookbook can be configured to contain cookbook-specific copyright, email, and license data.
- data_bags
- The data_bags/ directory is used to store all of the data bags that exist for an organization. Each sub-directory corresponds to a single data bag on the Chef server and contains a JSON file for each data bag item. If a sub-directory does not exist, then create it using SSL commands. After a data bag item is created, it can then be uploaded to the Chef server.
- environments
- The environments/ directory is used to store the files that define the environments that are available to the Chef server. The environments files can be Ruby DSL files (.rb) or they can be JSON files (.json). Use knife to install environment files to the Chef server.
- roles
- The roles/ directory is used to store the files that define the roles that are available to the Chef server. The roles files can be Ruby DSL files (.rb) or they can be JSON files (.json). Use knife to install role files to the Chef server.
We are going to use Knife command to manage our cookbooks. We need to tell Knife that where to find our chef cookbook directory.
Tapas@LINUXFUNDA /d/Chef-Repo $ mkdir .chef Tapas@LINUXFUNDA /d/Chef-Repo $ echo "cookbook_path [ 'D:\Chef-Repo\cookbooks' ]" > .chef/knife.rb Tapas@LINUXFUNDA /d/Chef-Repo $
We are done with configuring kinfe. Now we can use knife command to create a chef cookbook for us.
Tapas@LINUXFUNDA /d/Chef-Repo $ knife cookbook create LinuxFunda -C "Tapas Mishra" -m "tapas.mishra@linuxfunda.com" -I apachev2 -r md ** Creating cookbook LinuxFunda ** Creating README for cookbook: LinuxFunda ** Creating CHANGELOG for cookbook: LinuxFunda ** Creating metadata for cookbook: LinuxFunda Tapas@LINUXFUNDA /d/Chef-Repo
Verify that our cookbook got created or not
Tapas@LINUXFUNDA /d/Chef-Repo $ ls -l cookbooks/ total 4 drwxr-xr-x 1 Tapas Administ 4096 Nov 28 07:50 LinuxFunda -rw-r--r-- 1 Tapas Administ 3064 Sep 27 2013 README.md Tapas@LINUXFUNDA /d/Chef-Repo $
Conclusion:
We have installed all the required softwares on our Windows Host. In our next article i.e. in Part II we will start developing the Chef Cookbook on our Windows host as we have installed the Chef development Kit on it. After developing the chef cookbook we will start testing that cookbook on our Virtual machine which we will launch using Vagrant and Oracle Virtual Box.