So, what is the Vagrant ?
Vagrant is the Virtualization and Automation tool or software , that is to be very unique as compared to the other virtualization service and automation tool and it is very easy to learn this technology and there is the very big impact there to the other sources of Medium because it similar as a Docker and Ansible , Docker is the Virtulization tool and Ansible is the Automation Tool. and Vagrant is made up of Ruby Language that why it is still more powerful than other devops tool etc.
Why we use it?
1. It is very simple , easy to use.
2. sysntax is simple as compared to Docker and other automation Tool.
3. you can automate the task with simplly write the Bash shell command , that is Awsome .
4. It is a portable , it means that you can carry your vagrant box into your pendrive and cloud that make easier to use anywhere and anytime without worring the software dependencies and packages
How to install the Vagrant ?
steps 1. Go to the
vagrant Website ,download the software and choose your OS then install vagrant.
Step 2. After that Download
Virtual box from here ....and choose your OS.
Step 3. After downloading the virtual box install them. and follow the following commands !!!
Go to terminal and fire this commands ..
$ vagrant init
this commands will initialize the Vagrant file into your location
Then open the vagrant file and and write this sysntax...
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct:true # Nginx HTTP
config.vm.network :forwarded_port, guest: 443, host: 8443, auto_correct:true # Nginx HTTPS
end
IN this syntax the "ubutu/trusty6" is the vagrant box name and 'Vagrant.configure ("2") is the version name .....
and if you want to automate the task in the vagrant box ,then you need to write some Bash shell script and attach to the vagrant file... like this .
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct:true # Nginx HTTP
config.vm.network :forwarded_port, guest: 443, host: 8443, auto_correct:true # Nginx HTTPS
config.vm.network :forwarded_port, guest: 5000, host: 5000 # Flask debug server
config.vm.provision "shell" do |s|
s.path ="provision.sh"
end
end
In this Syntax "config.vm.provision "shell" do |s|
s.path ="provision.sh"
it describes the shell script path...
and you can write the shell script like this...given below
#!/bin/bash
echo "hello "
#update and upgrade the machine ..
sudo apt-get update
sudo apt-get upgrade
#and do whatever you want to install in vagrant box .....
Save this Bash script as a 'provision.sh' ....
Step: 4
Then go to terminal and Run the command ....
Then , this command will run your entire Bash script and downlaod the ubuntu os into this vagrant virtual machine ......and you can operate them as a operating system.......after that run ' vagrant ssh ' command and this command will let you in the vagrant box....
$ vagrant ssh
And Thats Done..!!! and if you want to know more vagrant commands
Go to the vagrant documentation