Quantcast
Channel: ROR – LinuxFunda
Viewing all articles
Browse latest Browse all 3

How to work with Chef using Oracle VirtualBox and Vagrant on a Windows host – Part I

$
0
0

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:

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.

Chef_Inst_1Click on Next

Chef_Inst_2Accept the License Agreement and Click on Next

Chef_Inst_3

Click on Next

Chef_Inst_4

Click on Install

Chef_Inst_5

It will take some time to complete the installation process. Click on Finish to complete.

Chef_Inst_6

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.

VirtualBox_Inst_1

Then Click on Next >

VirtualBox_Inst_2Click on Next >

VirtualBox_Inst_3Click On Next >

VirtualBox_Inst_4Click on “Yes”

VirtualBox_Inst_5Click on “Install”

VirtualBox_Inst_6

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.

Vagrant_Inst_1Click on Next

Vagrant_Inst_2

Accept the License Agreement and Click on Next

Vagrant_Inst_3Click on Next

Vagrant_Inst_4

 Click on Install

Vagrant_Inst_5It will take some time to complete the Setup. Click on the Finish button to Finish the Installation wizard.

Vagrant_Inst_6After 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.


Viewing all articles
Browse latest Browse all 3

Trending Articles