Vagrant What Is It?

Nov 1, 2025

Vagrant is a piece of software, that allows for easy building and tearing down of virtual machines from the command line. This makes the tool very good for spinning up, and tearing down test environments fast.

It can work with libvirt (QEMU), hyperV, Virtualbox and others. Though my personal testing, seems to show it working best with Virtualbox

Note that while Vagrant itself can work with multiple hypervisors, the image used has to be made for the chosen hypervisor.

Images can be found here: https://app.vagrantup.com/boxes/search There are both official images, and usercreated images (like dockerhub), so be mindful of which image is chosen.

Vagrant is in most distro’s repositories, so installing it is as simple as using the package manager.

URL: https://developer.hashicorp.com/vagrant

Where does Vagrant put the VM files

For virtualbox Vagrant will place the disks for the VMs in the virtualbox default disk folder. This folder can be changed in Virtualbox preferences.

Vagrant folder structure

Once vagrant is installed, we should create a folder where we want to keep our vagrant files (the files we use to define how we want the vm set up.)

Inside this folder, we should create subfolders for the vagrant boxes we want to use. Each folder should house its own Vagrantfile.

vagrant]$ tree
.
├── README.md
├── vagrant_MultiVM_Example
│   ├── files
│   │   └── vagrantKey.pub
│   ├── playbook.yml
│   ├── todo.md
│   └── Vagrantfile
└── vagrant_SingleVM_Example
    ├── files
    │   └── vagrantKey.pub
    ├── playbook.yml
    ├── todo.md
    └── Vagrantfile

We can either build the Vagrantfile from scratch, or we can have a default file created for us with the command “vagrant init”.

Creating the Vagrantfile

We can either build the Vagrantfile from scratch, or we can have a default file created for us with the command “vagrant init”. If we want to build the Vagrantfile from scratch, we should first take a look at the Vagrantfile documentation found here: https://developer.hashicorp.com/vagrant/docs/vagrantfile .

Post “vagrant up”, or Provisioning of VMs

One of the smart features of Vagrant is its ability to configure a VM after it has been brought up. This is called Provisioning in Vagrant terms. There are a few options for how Vagrant can handle this. Amongst them are “Shell commands”, “Puppet”, “Chef” and “Ansible”. Since I prefer ansible, that is what I will focus on here.

Telling Vagrant to use ansible to provision our virtual machines consists of two parts.

  1. a block in the Vagrantfile telling vagrant that we want to use Ansible, and the name of the playbook we want to use. This playbook should either be present in same folder as the Vagrant file, or in a subfolder.
config.vm.provision "ansible" do |ansible|
  ansible.playbook = "playbook.yml"
 end
  1. a playbook, that contains the Ansible plays we want to run on the newly created virtual machine. a few examples of what that could be: - creating a user we want present, and adding in public keys to said users authorized_keys file - installing and setting up desired software and services. - copying files from the host to the VM. - make sure the VM is patched up to the latest patch level. - whatever else we can do with Ansible.