Virtualbox Brew

Posted on  by admin

VirtualBox Virtualbox is a free and awesome virtualisation solution by Oracle. You can spin up multiple instance on your Mac using it, it’s very useful when you want to spin up different Operating System (OS) instances on your Mac such as Ubuntu/Centos/Windows etc. All you need is Operating System iso’s. Install Brew, VirtualBox, Vagrant and Vagrant-Manager, on a Macintosh 10.x Context: We will use Vagrant with VirtualBox. This guide is to help those unfamiliar with how to install and use Vagrant and Virtualbox setup. Install your RubyGems with gem and their dependencies with brew. “To install, drag this icon” no more. Homebrew Cask installs macOS apps, fonts and plugins and other non-open source software. $ brew install-cask firefox. Making a cask is as simple as creating a formula. Homebrew Docker Virtualbox (But not only VirtualBox) This formula resolves the Docker issue on AMD based MacOS (Ryzentosh). Also can be used on any Mac. Read writing from Jimmy Liao on Medium. 🏃Leisure Runner (completed full marathon. 12), 🤓Fullstack, 🐵 React Native / Golang / Node Practitioner, 🐧 Flutter Starter, Life-Hacker, DevOps Starter.

As mentioned in my first post, I’d like to try and build a Linux machine with Jenkins, GIT, Maven, Java and Docker.The end goal is to run Selenium WebDriver tests in dockerised containers. I have a lot to learn but I feel this is an area I need to grow my skill set.Also, as I work in test, I am also learning to use test-kitchen to execute infrastructure code.

The book I am learning from is Ansible From Beginner to Pro.I did encounter a few problems whilst following the book as versions of libraries have changed but I’ve managed to get past these errors so far.

This tutorial and the next few to follow have been completed on a Mac with OSX El Capitan. The steps on a Windows machine are likely to be different.

Goals

In this tutorial, we will:

  • Install VirtualBox
  • Install Vagrant
  • Install Ansible
  • Check it all works

Introduction

VirtualBox

Virtualisation allows multiple operating systems to simultaneously share your processor resources in a safe and efficient manner.VirtualBox is a provider for virtualisation and it allows your operating system to run in a special guest environment on top of your existing host operating system.In my case, the host operating system is OSX El Capitan.

Vagrant

Vagrant is an open source software for creating a portable development environment within minutes. It is useful for adevelopment team to mimic a server’s configuration locally. It can also be useful fortesting a version of Internet Explorer on a Mac for example.

Ansible

Ansible is a provisioning framework used to deploy software in a consistent manner in one or more machines.It ensures each machine is working with an identical environment.

Note:

I have used Homebrew to install the above mentioned software.Homebrew is a package managment system thatsimplifies the installation of software on the Mac operating system.

To install Homebrew, just follow the simple instructions on their website.

Step 1 - Install VirtualBox

In terminal, type in the following command

brew cask install VirtualBox

Step 2 - Install Vagrant

In terminal, type in the following command

brew cask install vagrant

Step 3 - Install Ansible

In terminal, type in the following command

brew install ansible

Step 4 - Check Installations were Successful

Type in the following commands and if the version is printed, then the installation was successful.

VBoxManage --version

Brew Virtualbox Install Fails

vagrant --version

ansible --version

My versions respectively are:

5.2.6r120293

Vagrant 2.0.1

ansible 2.4.2.0

Step 5 - Install an Ubuntu Server with Vagrant

Before we start using Ansible, we’ll need an environment which we can use to develop our new infrastructure. This is where we use Vagrant.

a. Create a new directory which will contain all your virtual machine installations. I normally put all my projects under a directory called development.Create a directory called virtualmachines and inside this create a directory called ansible-playbook:

mkdir virtualmachines && cd virtualmachines

mkdir ansible-playbook && cd ansible-playbook

On my machine, the full path looks like this:

/Users/pateli03/development/virtualmachines/ansible-playbook

b. To create the virtual machine on which you’re going to install packages and configure with Ansible, run this command:

vagrant init ubuntu/trusty64

This will create a file called Vagrantfile. We will be editing this file in Step 6 but this is what the contents of the file should look like (but with a lot more comments):

c. Finally, get Ubuntu Trusty up and running by executing:

vagrant up

When you execute this command the first time, a few things happen. First, it will check if a box with the name ubuntu/trusty64exists on your machine. If it doesn’t, it will download it from Atlas, a platform to host and discover Vagrant boxes.It is maintained by HashiCorp, the team behind Vagrant.

This could take a few minutes as this is downloading an entire operating system.

  • Once downloaded, Vagrant uses VirtualBox to create a virtual machine and boot it.

You can check the status of this virtual machine by running the command:

vagrant status

You can also log in to the machine using:

vagrant ssh

Virtualbox

This logs in to the machine using a known SSH key that was generated when the virtual machine was created.

To logout of this machine you can use the command exit

Step 6 - Hello Ansible

We need to let Vagrant know that we want to run Ansible on this virtual machine by adding some instructionsto the Vagrantfile. Go ahead and open the Vagrantfile in your favourite text editor but I recommend using Vim which isa text editor on Unix-like operating system. Vim has recently become important in my day-to-day life so it is another toolI would like to be more fluent in.

Open your Vagrantfile using this command:

vim Vagrantfile

Press i on your keyboard to insert text. You will see the bottom of the terminal window change to -- INSERT --

before the last end statement, add the following configuration:

It should look similar to this:

To save the changes:

press ESC on the keyboard to come back to command mode

then Shift + :

then w + q

then Enter to finish saving your changes.

(Note: Don’t enter the + symbol)

Step 7 - Creating the playbook

An Ansible playbook is a YAML file which contains a set of instructions to manage the configuration of remote machines.We will create a playbook now as using the same path specified in our Vagrantfile above – in a directory called provisioning.

mkdir provisioning && cd provisioning

touch playbook.yml

vim playbook.yml

press i on the keyboard to insert text

Copy and paste the below configuration code which will ping you virtual machine to confirm you can connect to it.

I’ll go into more detail on the configuration format in subsequent posts but be aware YAML syntax is whitespace sensitive.Tabs and whitespaces mean different things. YAML uses spaces and the suggested indentation is 2 spaces.

To save the changes:

Virtualbox Brewing

press ESC on the keyboard to come back to command mode

then Shift + :

Brew Virtualbox Update

then w + q

then Enter to finish saving your changes.

Step 8 - Running the playbook

You should now be able to run Ansible on your machine. Change directory one level up to the location of your Vagrantfile:

cd ..

vagrant provision

You should see something quite similar to the image below. Notice the ping task was successfully executed.

Boom! You’ve just provisioned your first virtual machine using Ansible and Vagrant.

Step 9 - Let’s look at VirtualBox

Virtualbox Brewers

As mentioned earlier, VirtualBox provides us with virtualisation and although it seems like we haven’t done anything with it,let’s have a look. Open the VirtualBox application (You can easily do this with Spotlight - cmd + space and type VirtualBox)

You should have something similar to this:

This is letting us know that Ubuntu Trusty is running properly. Happy days.

Brew Virtualbox-dkms

Summary

VirtualBox is the software which runs the Operating System and Vagrant acts as a wrapper around VirtualBox to manage it.Together, they can be used to create a local environment that matches your production environment or an environment toexecute Selenium Tests.

With our foundations in place - the next post will focus on using test-kitchen, a test harness used for testing infrastructure codeon isolated platforms. This is quite exciting, a TDD method to design infrastructure.


Commands used in this post

CommandDescription
brew cask install VirtualBoxInstalls VirtualBox using Homebrew
brew cask install vagrantInstalls Vagrant using Homebrew
brew install ansibleInstalls Ansible using Homebrew
VBoxManage --versionVersion of VirtualBox installed
vagrant --versionVersion of Vagrant installed
ansible --versionVersion of Ansible installed
vagrant init ubuntu/trusty64Initialise a virtual machine with Ubuntu Trusty
vagrant upStart a virtual machine
vagrant statusStatus of virtual machine
vagrant sshSSH into the virtual machine
vagrant provisionRun a playbook to provision the virtual machine
vim VagrantfileOpen a file called Vagrantfile with Vim text editor
touch playbook.ymlCreate a new file called playbook.yml


Virtualbox Brewery

Please enable JavaScript to view the comments powered by Disqus.