How to Install Vagrant on Centos 7/8 and Ubuntu 18
Getting Started
If you are running a home lab, it is inevitable that you will want to provision new VMs and would like to run your tests. There is always an option to create a golden image and then clone it if you need new VMs but why should you bother yourself to handle it all manually. Hashicorp already provides perfect automation for you, Vagrant. I do personally like it as you can keep all your infrastructure with Infrastructure as Code approach in your Vagrantfile
. So let's see how we can install vagrant on top of our hypervisor.
There is no official VirtualBox package for Ubuntu 20 while I am writing this post so I am skipping it
There are also some manual steps required to install libvirt vagrant plugin on Centos 8. That's why I am also skipping it, but you can refer to the official documentation if you want to install the plugin on Centos 8
Prerequisites
The first prerequisite is the obvious one: hypervisor. We first need to have a running hypervisor and you can refer to my post to install either KVM or VirtualBox. I personally prefer KVM over VirtualBox.
I again collected all the prerequisites under tasks/prereq.yaml
play:
Variables
As I prefer KVM
, I made libvirt
provider the default provider for the role. You can feel free to change the provider to virtualbox
in vars/main.yml
file.
Main Playbook
I will also follow my habit to divide plays into smaller pieces in my tasks/main.yml
file. I prefer to include operating system based plays in my main play.
Vagrant Installation on Centos 7/8
If your vagrant provider will be VirtualBox
, it is pretty straightforward. You will just need to install vagrant
. If you will be installing vagrant
for libvirt
provider, then you will need to install some dependencies. Thanks to the open-source community, there is a module supported by 100s of contributors here. This module will allow you run vagrant
commands under KVM
without any hassle.
Vagrant Installation on Ubuntu 18
If your vagrant provider will be VirtualBox
, it is pretty straightforward. You will just need to install vagrant
. If you will be installing vagrant
for libvirt
provider, then you will need to install some dependencies. Thanks to the open-source community, there is a module supported by 100s of contributors here. This module will allow you run vagrant
commands under KVM
without any hassle.
The module requires one of the source repositories to be enabled, but I couldn't find an easier way to only enable main source repository so I decided to enable all in /etc/apt/sources.list
but feel free to comment if you have a better solution. I could have used replace
module with backup
option and then could have restored the file after the installation is finished but I will handle it in a better way later. My exposure with Ubuntu / Debian administration is fairly new so I am sure there is a proper way to do it.
Putting things together
You can also use my Ansible roles to install vagrant along with the KVM or VirtualBox. You can download my roles with ansible-galaxy
and then add it in a playbook as below:
or
Last updated