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 -
- 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
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.
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 –
- Search any OS that you want to download.
- Copy the box URL
- 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 )
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 script – we 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”
3. Tweak in the vagrant file and removed unwanted configurations –
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 )
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 )
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 :)