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

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.

When you completed all the installations now use chef verify

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:

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.

We are done with configuring kinfe. Now we can use knife command to create a chef cookbook for us.

Verify that our cookbook got created or not

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.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
The following two tabs change content below.

Tapas Mishra

Sr. Engineer (DevOps)
Loves to work on Opensource products. Having experience on Linux environment. Knowledge on Public cloud services like AWS, Rackspace, DigitalOcean, Linode. Please don't hesitate to give a comment on the posts. Your comments are my strength.

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

  1. Do you know why I’m getting this error?

    $ vagrant plugin install vagrant-berkshelf –plugin-version 2.0.1
    Installing the ‘vagrant-berkshelf –version ‘2.0.1” plugin. This can take a few minutes…
    Bundler, the underlying system Vagrant uses to install plugins,
    reported an error. The error is shown below. These errors are usually
    caused by misconfigured plugin installations or transient network
    issues. The error from Bundler is:

    An error occurred while installing addressable (2.3.6), and Bundler cannot continue.
    Make sure that gem install addressable -v '2.3.6' succeeds before bundling.

    Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://rubygems.org/gems/addressable-2.3.6.gem)

    • Hi Igor, Have you installed ChefDK before installing the vagrant plugins? Please install the ChefDK first then install the berkshelf plugin. Also It is ok if you try with latest vagrant-berkshelf. Just issue the command vagrant plugin install vagrant-berkshelf. If you still having problem then please revert back with some more environment details like OS details and Vagrant version details. -Tapas

Leave a Reply