Vagrant is best utility to control backend virtual providers.  even in our  articles we  are talking  more  about Linux, we will make  this exception to this  Windows configuration  to continue our  Vagrant series

  • For example via vagrant you can control VirtualBox, vCloud Air, VmWare Fusion, AWS, Hyper-V, vSphere etc. virtual providers.
  • Boxes is predefined images which used by Vagrant to build environment. User can create own image and export this image for future or download ready image from internet.
  • Vagrantfile: This is instructions file which describe how to install and configure box. From this file we can configure resources for Virtual machine and provisioning type.

To download ready vagrant boxes use the following link:
http://www.vagrantbox.es/

Download and install vagrant for Windows. Use the following link: https://releases.hashicorp.com/vagrant/1.8.5/vagrant_1.8.5.msi

We will use git client for ssh connections. Download git for windows use the following link:
https://git-scm.com/download/win

Add environment variable for git and vagrant. We must add the following line for “path” environment variable:
C:\HashiCorp\Vagrant\bin;C:\Program Files (x86)\Git\bin

Add new box.
Firstly we must cerate folder for our box and go into this folder.
$ mkdir OEL7; cd OEL7

To show list of commands for vagrant use the following command:
$ vagrant list-commands

To show list of boxes which we can add, use the following command:
$ vagrant box list
OEL6.7 (virtualbox, 0)
centos6.7 (virtualbox, 0)
centos7 (virtualbox, 0)

Inititalize new “Vagrantfile“:
$ vagrant init
A Vagrantfile has been placed in this directory. You are now
ready to vagrant up your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
vagrantup.com for more information on using Vagrant.

Add new OEL box with OEL6.7 name from internet:
$ vagrant box add OEL6.7 http://cloud.terry.im/vagrant/oraclelinux-6-x86_64.box
==> box: Box file was not detected as metadata. Adding it directly…
==> box: Adding box ‘OEL6.7’ (v0) for provider:
box: Downloading: http://cloud.terry.im/vagrant/oraclelinux-6-x86_64.box
box: Progress: 100% (Rate: 2348k/s, Estimated time remaining: –:–:–)
==> box: Successfully added box ‘OEL6.7’ (v0) for ‘virtualbox’!

We must edit Vagrantfile as following:
$ cat Vagrantfile | egrep -v “#|^$”
Vagrant.configure(“2”) do |config|
config.vm.box = “OEL6.7”
end

Start box with name OEL6.7:
$ vagrant up

Go to the new OEL6.7 box with the vagrant ssh command:
$ vagrant ssh
Last login: Tue May 20 15:36:01 2014 from 10.0.2.2
[[email protected] ~]$

Add Ubuntu14.04 as new VirtualBoxVM.
$ mkdir Ubuntu14.04
$ cd Ubuntu14.04/
$ vagrant box add Ubuntu14_x64 “D:\Disk2\Downloads\software\OS\Vagrant-Boxes\ubuntu-14.04-amd64.box”
==> box: Box file was not detected as metadata. Adding it directly…
==> box: Adding box ‘Ubuntu14_x64’ (v0) for provider:
box: Unpacking necessary files from: file:///D:/Disk2/Downloads/software/OS/Vagrant-Boxes/ubuntu-14.04-amd64.box
box: Progress: 100% (Rate: 983M/s, Estimated time remaining: –:–:–)
==> box: Successfully added box ‘Ubuntu14_x64’ (v0) for ‘virtualbox’!

$ vagrant init Ubuntu14_x64
A Vagrantfile has been placed in this directory. You are now
ready to vagrant up your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
vagrantup.com for more information on using Vagrant.

Edit vagrantfile with the following lines:
$ cat Vagrantfile | grep -v ‘#’ | grep -v ‘^$’
Vagrant.configure(“2”) do |config|
config.vm.box = “Ubuntu14_x64”
# Forward request to host machine port 8080 to the guest machine port 80
config.vm.network “forwarded_port”, guest: 80, host: 8080
config.vm.network “public_network”
end

Show ssh configuration status:
$ vagrant ssh-config

Start boxes:
$ vagrant up
Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> default: Clearing any previously set forwarded ports…
==> default: Clearing any previously set network interfaces…
==> default: Available bridged network interfaces:
1) Intel(R) Ethernet Connection I217-LM
2) Microsoft KM-TEST Loopback Adapter
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
default: Which interface should the network bridge to?
default: Which interface should the network bridge to?
default: Which interface should the network bridge to? 2
==> default: Preparing network interfaces based on configuration…
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports…
default: 80 (guest) => 8080 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM…
==> default: Waiting for machine to boot. This may take a few minutes…
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest…
default: Removing insecure key from the guest if it’s present…
default: Key inserted! Disconnecting and reconnecting using new SSH key…
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM…
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly
default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces…

If you want to stop new created box the use the following command:
$ vagrant halt

If you want to delete virtual machine, use the following command:
$ vagrant destroy

If you want to delete box from vagrant list, use the following command(COS67 is the name of box):
$ vagrant box remove COS67

SHARE
Jamal Shahverdiyev, I was born in Azerbaijan. I have 10 years experience in IT especially in open source technologies. I have worked as a lead specialist in many important government projects. I am author of dozens of books about open source technologies in my native language and three of them have been published. I share my knowledge in universities regularly and teach Unix/Linux.

LEAVE A REPLY

Please enter your comment!
Please enter your name here