Vagrant in 2 Minutes

Roman Lazunin
3 min readFeb 8, 2021

--

Automated virtual machine provisioning on local machine or in cloud. Necessary tool for desktop app development and testing. Open source and free. Infrastructure as a code paradigm. Integrates with popular tools. Vagrant is a part of your devops toolbelt. Cross-platform. Provider independent.

Problem setup: a Windows desktop app which have to be tested for different Windows OS desktop and server versions. Current development workstation has older Windows 10 release. Current latest Windows 10 release is 20H2. Need to test with that. Also need to test my desktop app with Windows Server 2019.

What we also need is predictable and repeatable development or test environment. Should be able easily share among teams. Possible to put under revision or version source code control.

All that to put developer productivity to the next level.

Vagrant works with all different virtualization and cloud providers and by default uses VirtualBox on desktops. So you need to have VirtualBox installed and your PC machine have to be enabled and support CPU virtualization capabilities in order to start with virtualization.

Community provided public vagrant boxes can be found on vagrant box cloud at https://app.vagrantup.com/. You can search and choose a box which your want. I use one supported by Vagrant and referenced in Vagrant get started manual.

DISCLAIMER! To work with community resources is completely on your own risk and responsibility and can introduce security, data loss and similar risks! Using community resources makes your responsible for all license and copyright agreements for software used! Check with your IT organisation. If you are not sure you are enough competent — please do not do this at home or at work. Do it only on your own risk and responsibility! The purpose of this article and provided information and instructions are highly experimental.

If you will not use public box, which is much reasonable in many real life applications and scenarios, then you can set up internal or cloud repository for vagrant boxes and start to provision your own private boxes, which can require steeper start curve, but I believe will pay back soon. And there is good open source tools for that purpose which simplify and automate process a lot, but those are matter of other discussions.

To start with vagrant is quite simple. Create a separate folder for you vagrant box configuration file, change for public box in example above — execute a command:

$ vvagrant init hashicorp/bionic64

At this point you will get a default vagrantfile in your folder created by vagrant for this particular vagrant box. You can either use it ‘as is’ or go ahead and customize it with all necessary configurations for you test machine configuration, which can be everything possible, like CPUs, RAM, hard-drive, USB devices and serial ports, as well as features like shared folders. You change the file and you can check it in to your source code repo. Execute it whenever and everywhere locally or in cloud with different virtualization and cloud providers. And you can integrate it with different infrastructure provider tools like Chef, Puppet or Ansible.

When configuration file is ready all complex provisioning spins up with the one simplest command direct after:

$ vagrant up

You expected to have machine provisioned automatically at this point, which you can easily check if you start virtualbox. You should see your machine provisioned and running in either headless or terminal mode.

Those are the easiest introductory steps only necessary to get started with vagrant.

Happy provisioning!

SOURCES

  1. Vagrant home page, https://www.vagrantup.com/
  2. Vagrant in 5 minutes, youtube video, https://www.youtube.com/watch?v=wlogPKBEuUM
  3. Vagrant Crash Course, youtube video, https://www.youtube.com/watch?v=vBreXjkizgo
  4. Docker Vs Vagrant, youtube video, https://www.youtube.com/watch?v=9QGkJvbLpRA
  5. Vagrant and HashiCorp, Changelog Master Feed podcast, https://open.spotify.com/episode/3C8SqSiGTLj4MibA04bOCd

Originally published at https://www.linkedin.com.

--

--

Roman Lazunin

Senior IT professional, solutions architect, software developer, mentor, coach, M. Sc., Tech. Lic.