We continue  with this Wonderful series by  Jamal  from Azerbaijan, who wants to share  with you his  experience with vagrant and  most   of Visualization systems  ,  maybe you have to the bellow   links to  know  more  about install and  configure  Vagrant   :

Install Vagrant Ansible and Virtualbox in Feora 24/25

 

Create Box in Vagrant

 

Add your own created box to the vagrant images list(ub14x64.box is your own box file):
$ vagrant box add ub14x64 ub14x64.box
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|
config.vm.box = “ubuntu/trusty64”
end
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 bootstrap.sh 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|
config.vm.box = “ubuntu/trusty64”
config.vm.provision :shell,path: “bootstrap.sh”
end
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|
config.vm.box = “ubuntu/trusty64”
config.vm.provision :shell,path: “bootstrap.sh”
config.vm.network :forwarded_port, host:8080, guest:80
end
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|
config.vm.box = “ubuntu/trusty64”
config.vm.network “forwarded_port”, guest: 80, host: 8080
config.vm.provider “virtualbox” do |vb|
vb.gui = true
vb.memory = “1024”
end
config.vm.provision “shell”, inline: <<-SHELL
apt-get update
apt-get install -y apache2
SHELL
end

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
 

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