Vagrant — step by step tutorials.

Jay Bilgaye
3 min readJan 2, 2019

--

Everyone should use Vagrant. It simplifies a lot of things. No need to depend upon system administrator.

The world is changing and we must change with it. — Ragnar Lothbrok.

Going literally with the meaning of what Ragnar says, sysadmin guys can at least take a look at what is in store. Let me introduce the story of Vagrant for sysadmins. More helpful for developers actually.

  1. It can manage the lifecycle of a project.
  2. We can share machines.
  3. We can create stop halt machines.
  4. Helps in creating virtual machines in your local environment.
  5. It makes easy provisioning virtual machines with a shell script or SCM tools like chef or puppet.

This is all done with simple commands.

Ultimately, It gives you a consistent and stable development environment,

Below screenshot tells you a story in short which is simple and beautiful.

Vagrant: Simple and beautiful

Do bookmark the page: https://www.vagrantup.com/

Installation, follow: https://www.vagrantup.com/downloads.html

( FYI- I have downloaded Virtualbox in my machine for a demo from the link, https://www.virtualbox.org/wiki/Downloads )

Here, I'm using MacOs sierra, which demonstrates the use of Vagrant for you.

Create your First Vagrant machine.

Check your vagrant version:

Admin-1LM:~ $ vagrant — version
Vagrant 2.2.2
Admin-1LM:vagrant $ vagrant init centos/7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
Admin-1LM:vagrant $ grep config.vm.box Vagrantfile
config.vm.box = “centos/7”
Admin-1LM:vagrant $ vagrant up
Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> default: Box ‘centos/7’ could not be found. Attempting to find and install…
default: Box Provider: virtualbox
default: Box Version: >= 0
….Admin-1LM:vagrant $ vagrant box listcentos75-puppet387 (virtualbox, 20180831.0.0)
ubuntu/precise64 (virtualbox, 20170427.0.0)

Login to your First Vagrant machine.

Admin-1LM:vagrant jay$ vagrant global-status
id name provider state directory
— — — — — — — — — — — — — — — —-
6ba346c web virtualbox saved /Users/Admin/vagrant

SSH to Vagrant VM:

vagrant ssh 6ba346c

And you are good to use this machine for Configuring what ever you want. Try installing any software over it.

Let's see how to manage Boxes in Vagrant. You can discover boxes available at the website, https://app.vagrantup.com/boxes/search

Select Provider, select machine type and you are good to go with following commands,

e.g.

vagrant init centos/7
vagrant up

Or Create a file named as Vagrantfile in your new directory with content as,

Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
end

and, vagrant up

There are different providers available like ec2, google cloud, VirtualBox etc.

Different commands to manage box:

  1. vagrant box list
  2. vagrant box add
  3. vagrant box remove
Admin-1LM:vagrant $ vagrant box listcentos75-puppet387 (virtualbox, 20180831.0.0)
ubuntu/precise64 (virtualbox, 20170427.0.0)

Next, We will see how to manage SSH and Puppet module from Vagrant.

This series also includes GCP with Vagrant.

--

--