Plugin | Provisioning | Multiple VM's | Synced Folder | Part 2 | Intermediate | Vagrant Commands

Plugin | Provisioning | Multiple VM's | Synced Folder | Part 2 | Intermediate | Vagrant Commands

Plugin | Provisioning | Multiple VM's | Synced Folder | Part 2 | Intermediate | Vagrant Commands

 

Hello All, 

In this tutorial, we all will learn below topics related to vagrant. 

Part 2 includes - 
  • Plugin
  • Provisioning
  • Multiple VM's
  • Synced Folder
For an introductory session related to vagrant, basics command details are covered in Part 1 series of Vagrant - Visit here for Part 1.
  • vagrant help plugin - in order to check the help of plugin command.
  • vagrant plugin list - this command will list all of the installed plugins.
  • vagrant plugin install vagrant-vbguest - this command will install the plugin ( Plugin can be available in the GitHub ). 
  • vagrant plugin update [..name..(optional)] - a) update the specific plugin by specifying the name b) update the all plugin in one go without specifying the name. 
  • vagrant plugin uninstall vagrant-vbguest - in order to uninstall the plugin by specifying the name.
Random Bytes - 
  • When we are deploying some sort of web application in local VM then at the time, we need to access the website deploying in the local VM to the local machine.
    • To achieve this functionality - we can use the port forwarding concept.
    • config.vm.network "forwarded_port", guest: 80, host:8080
    • Allow accessing port 80 on guest via port 8080 on the host.
  • Disable vbguest update - to increase booting time.
    • config.vbguest.auto_update = false

Provisioning - 

We already discussed - what is vagrant provisioning in Part 1 of the vagrant introduction series.

Today we will see the different type of vagrant provisioner -
  • File Provisioning
    • config.vm.provision "file", source: "/scripts", destination: "/usr/scripts"
  • Shell Provisioning
    • Inline Script ( where bash script used within the vagrant file )
      • config.vm.provision "shell", inline: "echo Welcome to Random Skool"
    • Multiline Script -
                        $script = <<-SCRIPT
                        echo "Welcome to Random Skool"
                        sudo apt-get update -y
                        SCRIPT
                        Vagrant.configure("2") do |config|
                            config.vm.provision "shell", inline: $script
                        end
    • External Script -
      • config.vm.provision "shell", path: "randomScript.sh"
      • config.vm.provision "shell", path: "https://randomskool.com/random.sh"
Multiple VM - 

In order to setup multiple VM environment using Vagrant with virtualbox.

Two steps need to take care of -
  • Setup of Vagrant file for Multiple VM's
  • Controlling of Multiple VM's
Setup of Vagrant file for Multiple VM's

Multiple VM is one of the core features of Vagrant. In single vagrant we can define multiple VM as per requirements. 
Suppose as per requirement - we need to one box of Database and one box of Web ( do we need to need to create two different Vagrant files - No Need to create ). All we just need to define two different method in single Vagrant file. 
Due to this feature, it is very simple to manage Vagrant and we can declare N number of VM box.
   
Syntax:
    config.vm.define "web" do |web|
        web.vm.box = "nginx"
     end
    config.vm.define "database" do |db|
        db.vm.box = "mysql"
     end

Controlling of Multiple VM's
  • In order to ssh to the machine ( we cannot use vagrant ssh ) - now we need to mention the name of the machine as well.
    • vagrant ssh web
    • vagrant ssh database
  • Two different ways to boot machine -
    • All machine in one go
      • vagrant up
    • Specific Machine booting - need to mention name of the machine after vagrant up.
      • vagrant up web
      • vagrant up database
Random Bytes - 

When we are dealing with multiple VM's, we also need to take care of connectivity between different VM's. 
For setting up the communication between different VM's - need to setup network method within vm.define method.

config.vm.define "web" do |web|
        web.vm.box = "nginx"
        web.vm.network "private_network", ip: "192.168.50.4"
     end
    config.vm.define "database" do |db|
        db.vm.box = "mysql"
        db.vm.network "private_network", ip: "192.168.50.5"
     end

Synced Folder - 

As the name implies, Synced folder is used to maintain the syncing between guest folder and host folder. By default - everytime when we boot the VM using vagrant up it automatically create a shared folder named as vagrant and path is /vagrant. For additional Shared folder, we can use the synced method to setup different shared folders.
  • config.vm.synced_folder "salt/", "/src/salt"

Let me know your valuable feedback in the comment section of each blog post.

Follow us on instagram.com/randomskool

Join our telegram channel and group :) 

    Telegram Group: https://t.me/randomskoolQnA
    Telegram Channel: https://t.me/randomskool

0 Response to "Plugin | Provisioning | Multiple VM's | Synced Folder | Part 2 | Intermediate | Vagrant Commands"

Post a Comment

Hey Random,

Please let me know if you have any query :)

Adsense

Adsense

Adsense

Adsense