DevOps: VMs lifecycle management with Vagrant

My ultimate goal as a DevOps engineer is providing solutions focusing on aligning IT systems to company’s culture and business processes.  Limiting the time spent on creating bespoke tools and scripts that not all sysops are able to understand or maintain properly.  Any custom tool is hard to maintain without a basic software engineering background and  it needs a proper design, documentation, QA and all diligence and discipline required along the way.

From imperative to declarative

To achieve this result I need to shift from a developer mindset where is imperative (creating flows) writing programs or automation scripts to declarative,  specifying just the desired state of a system in a YAML or JSON files that are a “lingua franca” between devs and sysops providing an up-to-date documentation that can be safely managed on a SCM (like GIT).

Paradigm shift or just shifting problems?

Adopting a SCM is a first step to force to track all possible changes to our systems like any other program. The learning curve is quite steep to get there, but once started it will shortly prove that we are going in a more sustainable and scalable manner of managing IT Systems.

Labs Are Essentials

I like to use labs and they are an essential part in of my job in a way or another, when I have time to play with them of course.
Labs can leverage different technologies like virtualization and containers. I used to write some start-up scripts to spin proper labs following guides ( or simply Hydration Kit (
But being too familiar with a well known process is that you give for granted that other users can pickup the complexity, customise it according to their needs and eventually solve issues by themselves. But as you probably know, I was wrong.
So Instead of creating powershell scripts for provisioning VMs I started looking for alternatives.  In order to provide tools to colleagues that are abstracted by the platform or human readable (for a non-programmer), I found a framework by HashiCorp called Vagrant. It is great tool!

What is Vagrant?

Is cli utility/framework for managing the lifecycle of virtual machines.
It’s open source, it works with hyper-v, vm-ware, virtualbox.


Vagrant and Hyper-V Limitations

It will not create Network Switches, it will prompt the user for choosing the right connection. But you can create another Powershell script to run and fix it later on if needed.

How to manage all different VMs and describe that environment?

In my case my favourite tool is Ansible that is agent-less and uses SSH (linux) and WinRM (windows). For windows a big part of the package management is done be with chocolatey and powershell dsc.
In case your VM are just windows, maybe Boxstarter ( that leverages chocolatey it the way to go, especially if your configuration can be summarized in few lines of code in a gists.

Do you need a custom image?

Well, I suggest to use Packer:

Lab description

Create 4 VMs:
  1. Ubuntu 1804
  2. Centos 7
  3. Windows 2016
  4. Windows 2012 R2

How to spin up a LAB with Vagrant

Vagrant docs:
Create a Folder for your lab (all the VM will be stored under this path), I recommend a different drive from your OS (e.g. D,E, etc..) /
Edit the vagrant file

Spin up the environment with :


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.