Booting Vagrant
- What is Vagrant?
- Install Vagrant.
- Configuration of vagrant file
- Networking
- Add Plugin
- Provisioning
- Basic commands
What is Vagrant?
Vagrant makes the web development at ease for setting up the different component and share with others. The most take away with using vagrant is the ease of setup(provisioning) and saving the certain shapshot of your work ecosystem.
To use vagrant, virtualization software package is necessary - VirtualBox, VMWare..
Install Vagrant.
Vagrant shipped with support for VirtualBox,Hyper-V and Docker. Download Vagrant and install according to your operating system.
Configuration of vagrant file
Vagrant should be available in your path. Now create a vagrant file
This will use the default ubuntu box. If you want to use other box search at the hashicorp
With the above cmd a vagrant file should be generated with named Vagrantfile This file is core of the configuration of the vagrant where the virtual machine configuration is done with the Provisioning - preinstall all required package.
Networking
Basic Networking of the machine configuration at the Vagrant file are:
Forwading Port
if you want more port to be forwarded include these and optional protocal can also be define
Setup your Private Network
This allow host only access to the machine.
For more detail configuration on network refer at Vagrant Network configuration
Add Plugin
Install the virtual-box guest addition plugin for syncing the host directory.
Provisioning
Provisioning is setting up the machine to pre-install software packages and configure automatically. Different Provisioning are supported such as Shell,Puppet, Chef, Ansible, Salt, and Docker. Shell is default one. You can either define inline in the vagrantfie or in a separate script.
Inline shell script
Example of inline shell to update the debian and install Apache can be as :
External shell script
To use shell provision witht a external shell script:
Remote shell script
For Remote file:
Upload File
To upload a file to the guest machine from the host:
Puppet
Can perform in two types : Puppet Apply and Puppet Agent
Puppet Apply
Define the manifest and apply the provisioning. This will instruct vagrant that provisioning is going to be puppet.
And by default will look at the ‘manifest’ directory at the current directory and use the default.pp as the entry point.
Puppet Agent
This is defined as the puppet agent and you need to set the location of the puppet master.
And defined the node as:
Basic commands
The following are some of the basic commands of vagrant that will be used regularly.
Initilization
Bootup
SSH
This is ssh to the box with the default user/password vagrant/vagrant at default port 2222
.
Default root password vagrant
.
Suspending
This will save the current running state of the machine and stop it. When you are ready to begin working again, just run vagrant up
, and it will be resumed from where you left off.
Halting
This will gracefully shut down the guest operating system and power down the guest machine. You can use vagrant up
when you are ready to boot it again.
Destroy
This will remove all traces of the guest machine from your system. It’ll stop the guest machine, power it down, and remove all of the guest hard disks. Again, when you are ready to work again, just issue a vagrant up
Provisioning
On the first run of vagrant up
, if provision is defined it will run. If you want to rerun again then use the flag --provision
.
More on the vagrant cli