What is Vagrant ? Why Vagrant is important in DevOps World ? | Part 1 | Beginner | Vagrant Commands

What is Vagrant ? Why Vagrant is important in DevOps World ? | Part 1 | Beginner | Vagrant Commands

What is Vagrant ? Why Vagrant is important in DevOps World ? | Part 1 | Beginner | Vagrant Commands

What is Vagrant ? Why Vagrant is important in DevOps World ? | Part 1 | Beginner | Vagrant Commands


Hello All, 

In this tutorial, we all will learn complete vagrant in three different parts.

Part 1 includes - 
  • Introduction of vagrant
  • Why vagrant is used?
  • Different commands used in vagrant
  • Example - Provisioning using a simple bash script
Part 2 includes - 
  • Plugin
  • Provisioning
  • Multiple VM's
  • Synced Folder
Part 3 includes - 
  • Vagrant using SaltStack
  • Vagrant using Ansible

Introduction of Vagrant -

A vagrant is a tool for building and managing virtual machine environments in a single workflow.

Vagrant is used to setting up one or more virtual machines by:
  • Importing pre-made images (called "boxes")
  • Setting VM-specific settings (IP address, hostnames, port forwarding, memory, etc.)
  • Running provisioning software like Ansible and SaltStack.

Why vagrant is used?

Vagrant allows us very easily to share setups between team members allowing a very easy spin-up of a work environment. 
Suppose, one reason to use Vagrant is to test how your deployment works, i.e. provisioning, locally before pushing those changes to other environments.


Different commands used in vagrant

Vagrant Command for Quickstart –

1. vagrant init [name [url]] - initializes the current directory to be a Vagrant environment by creating an initial vagrant file.
     Example: vagrant init hashicorp/precise32

2. vagrant up - command creates and configures guest machines according to vagrant file.

3. vagrant status - command tells the state of the machine.

4. vagrant ssh - SSH into a running Vagrant machine.


Random Bytes -
By default, a vagrant creates a shared folder in Guest VM as /vagrant a to the local project folder.

Example - SSH into the Guest VM a cd /vagrant >> create a file touch random.txt >> logout >> the same file will be present to the local project folder.


5. vagrant suspend - Sleep/logoff the VM ( to start the VM à vagrant up )

6. vagrant halt - shutdown the VM ( to start the VM à vagrant up )

7. vagrant destroy - delete the VM

8. vagrant reload - restart the VM ( vagrant halt + vagrant up ).

Random Bytes -
In order to download other boxes – 
  1. Search any OS that you want to download.
  2. Copy the box URL
  3. vagrant box add {Title} {URL} - adds a box with the given address to Vagrant.

9. vagrant box list - to list all the installed VM images.

10. vagrant box remove {box title name} -  delete the VM box.

11. vagrant package - - output {title}.box
      Example. vagrant package --output custom-centos.box 
      ( preserve config changes that did in VM boxes )

12. vagrant box add Custom-Centos-7 custom-centos.box
       Change the entry in the existing vagrant file “config.vm.box” or remove the existing vagrant file 
       and create a new vagrant file using “vagrant init custom-centos”

13. vagrant box update - used in order to update the current box OS image to the latest version ( before destroying the VM )


VMBox Provisioning using Simple Bash Script -

In order to provision VM using Configuration management tools such as Ansible, SaltStack, or shell scriptwe can use vagrant provision.

1. Create a simple script in the same folder where the vagrant file located.

2. Create a script named “my.sh”

What is Vagrant ? Why Vagrant is important in DevOps World ? | Part 1 | Beginner | Vagrant CommandsWhat is Vagrant ? Why Vagrant is important in DevOps World ? | Part 1 | Beginner | Vagrant Commands

3. Tweak in the vagrant file and removed unwanted configurations –

What is Vagrant ? Why Vagrant is important in DevOps World ? | Part 1 | Beginner | Vagrant Commands

4. Run vagrant provision - command is a great way to quickly test any provisioners and is especially useful for incremental development of shell scripts, Ansible playbooks, and SaltStack ( in order to see any vagrant file configurational changes – need to destroy and up it again )


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 "What is Vagrant ? Why Vagrant is important in DevOps World ? | Part 1 | Beginner | Vagrant Commands"

Post a Comment

Hey Random,

Please let me know if you have any query :)

Adsense

Adsense

Adsense

Adsense