When starting with chef-solo it is best to practise it on a virtual machine.
A virtual machine gives us freedom to gets our hands dirty without creating a mess on the actual computer.
The virtualization software that we will be using is known as VirtualBox.
Now using VirtualBox we can install and run any operating system on our PC/Host computer.
The OS running inside the VirtualBox is the guest OS and the OS running the entire thing is the Host OS.
When you install an operating system in VirtualBox there is a lot of clicking around is involved, which brings us to vagrant.
Vagrant is a software that connects with VirtualBox and installs the OS inside the VirtualBox as configured by the developer in the Vagrant file and can also install software and run custom commands.
This gives the developer freedom to write once and spin off multiple guest OS with no additional effort.
In case of a script/guest OS failure, this also makes it easy to destroy/delete the guest OS and restart.
Required Software
Download a vagrant Linux flavour
I will use Ubuntu precise 64
Optional, Putty, to login to your virtual machine
Checking Installation
Once installation is complete (assuming you are using windows without Cygwin) open command prompt else open Cygwin terminal.
Now on command prompt enter command
1
vagrant
You will see something like this and more.
1
Usage: vagrant [-v] [-h] command [<args>]
This means your vagrant installation was successful, and it is ready to use.
- Add Guest OS
Vagrant has a concept of box, it is the Linux image that you downloaded at required software section.
So currently executing command, vagrant box list, will not show any anything.
1
$ vagrant box list
This will not show anything since we have not added any guest OS images.
Now let’s add the Linux box image you downloaded at required software section.
First via command line go to the folder where your Linux image was downloaded.
Execute the below command to add the downloaded file to vagrant.
1
$ vagrant box add precise64 precis64.box
The above command is, vagrant box add
Now to check that the image has been added successfully execute
1
$ vagrant box list
This will show precise64 on the list, since that is the name we gave while adding it.
- Guest OS Setup
The steps to configure a default guest OS via vagrant are
Create a folder where we will configure our guest OS
1
2
3
$ mkdir testBox
$ cd testBox
Initialise vagrant file in above created folder
1
$ vagrant init precise64
This will create a “Vagrantfile” on your current location. This file is the heart of your virtual machine.
The structure of this command is
1
$ vagrant init <name of box you added in add guest OS step above>
- Boot Guest OS
Start vagrant from the above folder so that it reads the initialised vagrant file and boots up the guest OS.
Execute
1
$ vagrant up
This command will read the VagrantFile created by the vagrant init command and will try to boot the Guest box with name “precise64”.
You will see output like this.
1
2
3
4
5
6
7
8
9
10
11
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant
Note:
In case you get Mismatch_native error,
Please check virtualbox forum
Else as per above output you can see that vagrant has forwarded the virtual machine SSH port 22 to 2222.