June 13, 2018

Basic Chef + Test Kitchen: Setting up Ubuntu with Vagrant + Virtual Box + the Test-Kitchen Ruby Gem on a MacBook

Let's say we wanted to test something out on Ubuntu, a popular Linux distribution, on a MacBook: How would we be able to set it up locally, configuring the workstation? We set it up in Docker before. What other ways are there?

One way to do it is with a Chef.io tool to spin up a test environment, Test-Kitchen, and its Ruby gem. And, yes, this cooking metaphor is extended all throughout the Chef toolset with its cookbooks and recipes for environment configurations.

Adventures in Automation started looking at The Ruby Behind Chef, the History Behind Test Kitchen, and exploring the free tutorials that Chef provides, the extensive Learn Chef Rally.

For this article we will be using:
  • Test-Kitchen on GitHub as a primary source: builds a Vagrantfile, allowing you to create or destroy the instances of your virtual machines
  • Vagrant: "a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the "works on my machine" excuse a relic of the past".
  • Oracle's VirtualBox: "VirtualBox is a cross-platform virtualization application. What does that mean? For one thing, it installs on your existing Intel or AMD-based computers, whether they are running Windows, Mac, Linux or Solaris operating systems. Secondly, it extends the capabilities of your existing computer so that it can run multiple operating systems (inside multiple virtual machines) at the same time."

Setting Up The Environment

Once you have Ruby and VirtualBox installed, setting up a new virtual machine only takes four commands, according to the Test Kitchen - Quick Start guide at https://github.com/test-kitchen/test-kitchen:
  • gem install test-kitchen
  • kitchen init
  • kitchen list
  • kitchen converge default-ubuntu-1604

Step One: Setup Pre-Requisites



1.1.  Install Ruby: Follow the instructions here. Check that it is working by typing in using the Mac Terminal, or the Linux command line interface: ruby -v

1.2.  Install VirtualBox: Get the latest version of VirtualBox, and download the Mac or Linux version you need. 

1.3. Create New Directory: Create a new subfolder in the home directory such as test-kitchen-demo, by:  mkdir ~/test-kitchen-demo

1.4. Enter the New Directory: Change to the new directory with: cd  ~/test-kitchen-demo

Step Two: Install and Run Kitchen


2.1.  Install the test-kitchen gem: The last release at the time of this article was May 7, 2018 with 1.21.2, according to RubyGems.orggem install test-kitchen
  • This will install all the Ruby dependencies that the Test-Kitchen project needs to execute. 
2.2. Intialize a new Kitchen projectkitchen init
  • The kitchen-vagrant Ruby gem will install. According to its GitHub site, "[t]his driver works by generating a single Vagrantfile for each instance in a sandboxed directory. Since the Vagrantfile is written out on disk, Vagrant needs absolutely no knowledge of Test Kitchen. So no Vagrant plugins are required". It has built in support for VirtualBox, VMware and many others. 

2.3. List All Virtual Machines:  Want to see a listing of all virtual environments you can bring up? kitchen list
  • Two virtual machines can be found: default-ubuntu-1604 and default-centos-7.
2.4. Bring Up A Virtual Machine: We can use the command: kitchen converge default-ubuntu-1604
  • The base VirtualBox is downloaded from bento/ubuntu-16.04 and updated
  • The virtual machine is booted up
  • Vagrant instance is created for default-ubuntu-1604
  • Chef Omnibus is downloaded and installed from https://omnitruck.chef.io/install.sh
  • The virtual images is now up. 
2.5. Verify Server in VirtualBox:  If you bring up VirtualBox, you can see that a virtual machine is now running


... After you are done, makes sure to destroy your servers: kitchen destroy

How Does This All Work?

Vagrant Boxes: 


Have you ever ordered at a Japanese restaurant a Bento box for lunch, an all-in-one assortment of rice, veggies, and sushi, everything neatly organized in its own compartment?

Chef.io has a Bento project at https://github.com/chef/bento, creating templates for building Vagrant boxes. If you go to Vagrant Cloud / Bento, at https://app.vagrantup.com/bento, you can see environments for:
  • bento/centos-6.7
  • bento/fedora-28
  • bento/centos-7.5
  • bento/debian-9.4
  • bento/ubuntu-14.04
... And many more Linux distributions.

From VagrantUp's documentation about Boxes:

"Boxes are the package format for Vagrant environments. A box can be used by anyone on any platform that Vagrant supports to bring up an identical working environment.

"The vagrant box utility provides all the functionality for managing boxes. You can read the documentation on the vagrant box command for more information.

"The easiest way to use a box is to add a box from the publicly available catalog of Vagrant boxes. You can also add and share your own customized boxes on this website.

"Boxes also support versioning so that members of your team using Vagrant can update the underlying box easily, and the people who create boxes can push fixes and communicate these fixes efficiently".


You can search for more boxes on the VagrantCloud, https://app.vagrantup.com/boxes/search

Kitchen-Vagrant Ruby Gem



Installing the Kitchen Driver for Vagrant and running Kitchen Init creates a new kitchen.yml file:

kitchen.yml
 driver:  
  name: vagrant  
 provisioner:  
  name: chef_solo  
 platforms:  
  - name: ubuntu-16.04  
  - name: centos-7  
 suites:  
  - name: default  
   run_list:  
   attributes:  

What is Chef-Solo? It is a Chef product that allows you to install and configure all packages needed without setting up a Chef server. "Chef Solo is ideal for people who are already experienced with Chef, already have Chef cookbooks, or are looking to learn Chef", and is part of the Chef Development Toolkit at https://downloads.chef.io/chefdk.

What is converge?

"The chef-client configures the system based on the information that has been collected. Each resource is executed in the order identified by the run-list, and then by the order in which each resource is listed in each recipe. Each resource in the resource collection is mapped to a provider. The provider examines the node, and then does the steps necessary to complete the action. And then the next resource is processed. Each action configures a specific part of the system. This process is also referred to as convergence. This is also referred to as the 'execution phase'". - Chef.io / Chef Client Overview

Check Out Learn Chef Rally!


Want to dig a bit deeper? Take a look at Learn.Chef.io, and Applying a Cookbook Locally. There, you can learn about:
  • Writing a web server cookbook that prints out a "Hello World" message to the screen.
  • Installing an Apache webserver with a cookbook.
  • Examining the parts of a Test Kitchen file.
  • Creating a test instance of kitchen.
  • Applying a cookbook to a Test Kitchen instance.
  • Verifying the instance is converged as expected.
  • Deleting the Test Kitchen instance when done.


Enjoy! Happy Testing!

-T.J. Maher
Sr. QA Engineer, Software Engineer in Test
Meetup Organizer, Ministry of Testing - Boston

Twitter | YouTubeLinkedIn | Articles

27 comments:

Alia parker said...

Household appliances make our lives easier. As a matter of fact, most of us can't live without these units. Primarily, we use appliances to save a lot of time so we can enjoy our hobbies and spend time with our loved ones. 3 shelf carts

homework assignment help said...

Interesting article. It is rather unfortunate that over the last decade, the travel industry has had to fight terrorism, SARS, tsunamis, bird flu, swine flu, and also the first ever real global economic downturn.

coursework service said...

Succeed! It could be one of the most useful blogs we have ever come across on the subject. Excellent info! I’m also an expert in this topic so I can understand your effort very well. Thanks for the huge help.

Martin Luiz said...

We have master task scholars because of which we can give the best assistance to the tasks in the pay to get assignment done UK to our clients. Understudies who need amazing outcomes recruit our schoolwork composing administration and become tranquil, as they probably are aware, we will not at any point lead them to go towards disillusionment. By picking us, clients are blissful and fulfilled all the time with the astute choice they made as they achieve the top grades with the schoolwork arranged by us.

Anonymous said...

The tough enrollment process has made it workable for us to enlist the best writers of the town. We make them go through a few screening stages to Cheap Assignment Writing Service in UK guarantee they are the ideal fit to give task help to the tutees. Their capacity to extricate rewarding pointers from true and real sources empowers them to make the best piece out of paper for each request. Likewise, their significant information about their area is another incidental advantage empowering them to land great outcomes.

rogue one orson krennic jacket for sale said...

There is a plane coat associated with Gale Anne Hurd's faction exemplary film The Terminator. It was given as a gift in the wake of shooting to her creation colleague and has a letter from Pacific Western Productions saying thanks to them for their persistent effort, it is an extraordinarily uncommon and huge relic from this persuasive sci-fi film.

Do My Essay from EssayEmpire said...

These tasks can get found out with counterfeiting apparatuses and the understudy can be punished. Be that as it may, with us, there are no possibilities getting discovered utilizing an exposition composing administration.

SOIL MODIFICATION services in USA said...

Numerous methods can be used to modify soil, such SOIL MODIFICATION services in USAas tillage, composting, and surface application of amendments.

Trade finance in Dubai said...

The inability of firms to grow and expand isTrade finance in Dubai caused by a shortage of working cash.

Esports Dubai said...

Four04esports is currently able to enthral fans all over the world with its great coverage thanks to its workforce of more than 140 Esports Dubaiprofessionals and its more than 15 million monthly visitors.

Ramma Foundation Repair said...

Ramma Charity is a situation and organisation that offers facilities for gutter cleaning, crack repair, and snow removal. In Alberta, we advance as the cornerstone for deferment repair. foundation repair Edmonton

leadingit said...

Using Test-Kitchen with Chef.io is a great way to quickly set up a test environment for Ubuntu on a MacBook. This approach allows for easy configuration of the workstation and can save time in the long run. Withleadingit company in Dubai, businesses can get expert support in implementing such solutions for their IT infrastructure.




Charbonnel said...

Setting up Ubuntu on a MacBook can be achieved through various methods besides using Docker. One alternative is to install Ubuntu natively on the MacBook, either by creating a dual-boot configuration or using virtualization software like VirtualBox. Exploring these options while savoring the delightful flavors of belgian chocolate in Khobar can make the setup process even more enjoyable and rewarding.

arixdigital said...

Setting up Ubuntu with Vagrant, Virtual Box, and Test-Kitchen is a powerful combination for efficient development and testing. To ensure maximum visibility and reach for your projects, consider utilizingseo services dubai.

blink camera login said...

If you have any of issues related zumimall camera app and tethys cam setup troubleshooting tips will help you to fix the issues as fast as possible.

http //edimax.setup said...

Launch an Internet browser such as Microsoft Internet Explorer or Mozilla Firefox. In the address bar, type edimax.setup or edimaxext.setup and press enter.

myfritz said...

Haben Sie Probleme mit den http //fritz.box Konfigurationen? Machen Sie sich keine Sorgen, wir sind jederzeit für Sie da, wenn Sie fachkundige Unterstützung bezüglich der fritzbox 7490 login und deren Konfigurationen benötigen.

Editing Help UK said...

As assignment taskers, we excel in delivering top-tier academic solutions tailored to your specific requirements. Our team of expert writers is dedicated to meticulous research, impeccable writing, and timely delivery, ensuring your assignments not only meet but exceed your expectations. With a focus on originality and excellence, we are committed to helping you achieve academic success. Trust us to be your partners in educational excellence. editing help best online academic writing

Combined Pump said...

Embarking on testing something out on Ubuntu is like an exciting voyage into the realm of technology. Just as we explore the Ubuntu system, hydrocarbon pumps Aberdeen navigate the intricate world of oil and gas, ensuring a smooth flow of resources. Both journeys signify the pursuit of excellence, embracing innovation and precision to create a more efficient and prosperous future.

Mark Antony said...

Fantastic guide to setting up Ubuntu on a MacBook using Test-Kitchen and Chef tools! The step-by-step instructions, along with the insightful explanations, make it easy for anyone to configure a virtual environment for testing. Kudos for simplifying a complex process!
Impugnado Divorcio Estado de Nueva York

lalosalamanca21 said...

"An insightful guide on setting up Ubuntu for testing with Chef's Test-Kitchen and Vagrant on a MacBook. The step-by-step instructions, along with explanations of Vagrant boxes and Chef-Solo, make it an excellent resource for developers exploring local environment configurations."
abogado de delitos sexuales de fairfax

johnblaze21 said...

Great guide on setting up Ubuntu using Test-Kitchen, Vagrant, and VirtualBox on a MacBook.
New York NY Divorce Attorneys

Alexander_01 said...

In the culinary world of software development, mastering the Basic Chef and Test Kitchen tools is essential. On a MacBook, setting up Ubuntu with Vagrant and VirtualBox alongside the Test-Kitchen Ruby Gem is a recipe for success, ensuring a seamless environment for testing and refining your delicious code creations. "Your comment is like a burst of confetti, adding joy to our blog. Each word is a brushstroke on the canvas of conversation, creating a vibrant tapestry of ideas. We eagerly await your next insight, as your contributions light up our digital world. Thanks for being our comment superstar!"appealing a protective order in virginia

Future Style said...

Future Style By Nida Faysal is the epitome of creative elegance, fusing modern styles with classic refinement. Each item offers a window into the direction that fashion will go by fusing heritage and innovation.

Amy Jhons said...

orange drug possession lawyerHaving to deal with drug ownership penalties in Orange District? A talented medication ownership attorney can be critical in exploring the intricacies of the general set of laws. They give master exhortation on your privileges, challenge proof, and haggle with examiners to look for decreased charges or option condemning choices. With a profound comprehension of California's medication regulations and nearby court methodology, an accomplished lawyer can assist with relieving likely punishments and work towards the most ideal result for your case. Counsel a devoted legal counselor to safeguard your future.

Trufleers said...

I recently enjoyed a cup of قهوة عربية, and it was a delightful experience! The aromatic blend and rich flavor captured the essence of traditional Arabic coffee perfectly. A must-try for anyone who appreciates authentic coffee!

Advina Logan said...

A virginia child pornography lawyer focuses on defending people who are accused of possessing, distributing, or creating child pornography. Serious consequences for these offenses include mandatory registration as a sex offender, substantial fines, and long jail terms. A skilled lawyer meticulously reviews the evidence, contests any unlawful searches, and bargains with prosecutors to lower the charges. They strive to minimize the impact of the charges and pursue the best possible legal outcome while defending the rights of their clients.