Vagrant first steps

Vagrant install and configure

Vagrant create box file

Add your own created box to the vagrant images list( is your own box file):
$ vagrant box add ub14x64
Look at the new added box file:
$ vagrant box list
ub14x64 (virtualbox, 0)
To delete already created virtual machines use the following command:
$ vagrant destroy
lb: Are you sure you want to destroy the ‘lb’ VM? [y/N] y
==> lb: Destroying VM and associated drives…
ngweb2: Are you sure you want to destroy the ‘ngweb2’ VM? [y/N] y
==> ngweb2: Destroying VM and associated drives…
ngweb1: Are you sure you want to destroy the ‘ngweb1’ VM? [y/N] y
==> ngweb1: Destroying VM and associated drives…
Get fresh Ubuntu14.04 machine and start this machine with Virtualbox provider:
$ vagrant init ubuntu/trusty64
$ vagrant up –provider virtualbox
After first download of box from internet it will be used from local disk and will not go to the internet at the second time.
Now we have two box in the list:
$ vagrant box list
ub14x64 (virtualbox, 0)
ubuntu/trusty64 (virtualbox, 20161121.0.0)
Login to the new created virtual machine from host machine with vagrant:
$ vagrant ssh
Shutdown new created machine:
$ vagrant halt
Create new generic Vagrant file:
$ mkdir vagrant-temp
$ cd vagrant-temp/
$ vagrant init
To use vagrant with ubuntu/trusty64 machine we must write the following lines into the Vagrantfile file:
Vagrant.configure(“2”) do |config| = “ubuntu/trusty64”
By default vagrant will synchronize local folder with Vagrantfile to the virtual machine /vagrant folder.
If you want SHELL provisioning in start time use the following syntax in your Vagrantfile(The file must be placed in the local folder with Vagrantfile and in the start time will be synced to the virtual machine /vagrant folder then will be executed there):
Vagrant.configure(“2”) do |config| = “ubuntu/trusty64”
config.vm.provision :shell,path: “”
If you want to forward port to the virtual machine use the following syntax. It will open port 8080 in the host machine and will forward to the port 80 on the guest machine:
Vagrant.configure(“2”) do |config| = “ubuntu/trusty64”
config.vm.provision :shell,path: “” :forwarded_port, host:8080, guest:80
After adding port forward you must reload the virtual machine with vagrant:
$ vagrant reload
Save the current state of the virtual machine:
$ vagrant suspend
Start Ubuntu machine with gui, forward port 8080 to the virtual machine 80 port, update packages and install apache2 package:
$ cat Vagrantfile | egrep -v ‘^#|^ #|^$’
Vagrant.configure(“2”) do |config| = “ubuntu/trusty64” “forwarded_port”, guest: 80, host: 8080
config.vm.provider “virtualbox” do |vb|
vb.gui = true
vb.memory = “1024”
config.vm.provision “shell”, inline: <<-SHELL
apt-get update
apt-get install -y apache2

Check result with the following command and you will see the first page of apache web server:

$ curl http://localhost:8080
Show all boxes in the host machine:

$ vagrant global-status
id name provider state directory

67a2330 default virtualbox poweroff /home/jshahverdiev/vagrant-zibilxana
7e167e2 ansible virtualbox running /home/jshahverdiev/vagrant-zibilxana/ansible-and-webserver
94d2d6a webserver virtualbox running /home/jshahverdiev/vagrant-zibilxana/ansible-and-webserver


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s