Vagrant Tutorial

Ratings:
(4.4)
Views:764
Banner-Img
  • Share this blog:

Vagrant is a great open source software for configuring and deploying multiple development environments. It works on Linux, Mac OS X, or Windows and although by default it uses VirtualBox for managing the virtualization, it can be used with other providers such as VMware or AWS.

Vagrant Overview

Vagrant is a very good wrapper around Oracle's VirtualBox. It makes life easier for web developers and the like by providing a nice command-line interface to build, manage, provision, use virtual machines.

Although it can use other virtual machine software, the most commonly used is VirtualBox. VirtualBox allows you to create a virtual server right on your machine. This allows you to run a Linux server (or whatever else you would like) on your personal Mac or PC.

Vagrant is essentially the glue between provisioning software such as Puppet or Chef and VirtualBox.

Vagrant helps you configure your network configurations for VirtualBox as well as run the necessary scripts to provision your virtual machine.

 

Provisioning your Vagrant Machine:

Launching a blank virtual machine is not very useful, so Vagrant supports provisioning virtual machines through the use of provisioners. There are a handful of provisioners for the most common choices supported out of the box with Vagrant

  • Chef Solo
  • Chef Server
  • Puppet Standalone
  • Puppet Server
  • Shell

You can also use multiple provisioning options on the same VM. For example, you can provision your box using Chef and then finish your provisioning with a shell script afterwards.

 

Vagrantfile

Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines. Vagrantfiles are called Vagrantfiles because the actual literal filename for the file is Vagrantfile

Vagrantfile is supposed to be committed to version control.

Other developers involved in the project to check out the code, run vagrant up, and be on their way.

 

Vagrant configuration

Configuration versions are the mechanism by which Vagrant 1.1+ is able to remain backwards compatible with Vagrant 1.0.x Vagrantfiles, while introducing dramatically new features and configuration options.

Vagrantfile will be in roughly the following format:

Vagrant.configure("2") do |config| # ... end

The "2" in the first line above represents the version of the configuration object config that will be used for configuration for that block (the section between the do and the end).

The important thing to understand as a general user of Vagrant is that within a single configuration section, only a single version can be used.

You cannot use the new config.vm.provider configurations in a version.

 -configuration section. Likewise, config.vm.forward_port will not work in a version

 -configuration section (it was renamed).

This is useful if you found some useful configuration snippet or something that you want to use.

Vagrant.configure("1") do |config| # v1 configs... end Vagrant.configure("2") do |config| # v2 configs... end

Vagrant Features

This is a list of features specific to Vagrant that Atlas provides.

  • Vagrant Share
  • Vagrant Box Versioning
  • Vagrant Box Catalog
  • Vagrant Box Creation

 

Vagrant Share: 

The vagrant share command, you can instantly share public access to your running Vagrant environment (virtual machine). The canonical use case for this is to share SSH or HTTP access to your machine.

It's important to share your work with colleagues or clients throughout the development process. Vagrant makes this easy with the share command.

There are several different types of shares.

 

HTTP Sharing

Vagrant Share shares HTTP access to your Vagrant environment to anyone in the world. The URL that it creates is publicly accessible and doesn't require Vagrant to be installed to access -- just a web browser.

$ vagrant share ==> default: Local HTTP port: 5000 default: Local HTTPS port: disabled ==> default: Your Vagrant Share is running! ==> default: URL: http://frosty-weasel-0857.vagrantshare.com ...

Currently, HTTP access is restricted through obscure URLs. We'll be adding more ACLs and audit logs for this in the future.

 

SSH Access

Vagrant Share can allow anyone to easily SSH into your Vagrant environment. You're having issues where your app isn't running properly or you just want to pair program. Now, with just one flag, anyone you want can SSH into your Vagrant environment from anywhere in the world.

To enable sharing SSH, you must add the --ssh flag to vagrant share:

$ vagrant share --ssh
==> default: SSH Port: 22
==> default: Generating new SSH key...
    default: Please enter a password to encrypt the key:
    default: Repeat the password to confirm:
    default: Inserting generated SSH key into machine...
==> default: Checking authentication and authorization...
==> default: Creating Vagrant Share session...
    default: Share will be at: awful-squirrel-9454
==> default: Your Vagrant Share is running!
...

The --ssh flag is provided, Vagrant generates a brand new SSH keypair for SSH access. The public key portion is automatically inserted into the Vagrant environment. The private key portion is uploaded to the server managing the Vagrant Share connections. The password used to encrypt the private key is not uploaded anywhere, however, meaning we couldn't access your VM if we wanted to. It is an extra layer of security.

$ vagrant connect --ssh awful-squirrel-9454
Loading share 'awful-squirrel-9454'...
Password for the private key:
Executing SSH...

Welcome to Ubuntu 12.04.1 LTS

 * Documentation:  https://help.ubuntu.com/
Last login: Wed Feb 26 08:38:55 2014 from 192.168.148.1
vagrant@precise64:/vagrant$

 

General Sharing (Vagrant Connect)

Vagrant share can share any TCP/UDP connection, and is not restricted to only a single port. When you run vagrant share, Vagrant will share the entire Vagrant environment.

When the person you are sharing with runs vagrant connect SHARE-NAME, Vagrant will give this person a static IP they can use to access the machine as if it were on the local network:

$ vagrant connect awful-squirrel-9454
==> connect: Connecting to: awful-squirrel-9454
==> connect: Starting a VM for a static connect IP.
    connect: The machine is booted and ready!
==> connect: Connect is running!
==> connect: SOCKS address: 127.0.0.1:62167
==> connect: Machine IP: 172.16.0.2
==> connect:
==> connect: Press Ctrl-C to stop connection.
...

Security Concerns

The primary security mechanism for Vagrant Share is security through obscurity along with an encryption key for SSH. Additionally, there are several configuration options made available to help control access and manage security:

In addition to these options, there are other features we've built to help:

  • Vagrant share uses end-to-end TLS connections. So even unencrypted TCP streams are encrypted through the various proxies and only unencrypted during the final local communication between the local proxy and the Vagrant environment.
  • SSH keys are encrypted by default, using a password that is not transmitted to our servers or across the network at all.
  • SSH is not shared by default, it must explicitly be shared with the --ssh flag.
  • A web interface we've built shows share history and will show basic access logs in the future.
  • Share sessions expire after a short time (currently 8 hours), but can also be expired manually by ctrl-c from the sharing machine or via the web interface

 

Vagrant Box Versioning

Boxes support versioning so that members of your team using Vagrant can update the underlying box easily, and the people who create boxes can push fixes and communicate these fixes efficiently. There are multiple components of a box:

  • The box itself, comprised of the box name and description.
  • One or more box versions.
  • One or more providers for each box version.

Upon vagrant up or vagrant box outdated, an out-of-date box user will see the following message in Vagrant:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'hashicorp/example' is up to date...
==> default: A newer version of the box 'hashicorp/example' is available! You currently
==> default: have version '0.0.5'. The latest is version '0.0.6'. Run
==> default: `vagrant box update` to update.
...

Box Version Release States

Create new versions of boxes without releasing them or without Vagrant seeing the update. This lets you prepare a box for release slowly. Box versions have three states:

unreleased: Vagrant cannot see this version yet, so it needs to be released. Versions can be released by editing them and clicking the release button at the top of the page

active: Vagrant is able to add and use this box version

revoked: Vagrant cannot see this version, and it cannot be re-released. You must create the version again

 

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox