Automate VM creation with Vagrant

William Albertus Dembo
3 min readApr 3, 2019

--

A virtual machine (VM) is an emulation of a computer system

Have you ever create some virtual machine on your computer manually? If you ever did this then you’ll know how painful the process is, download the image, create the VM, set VM resources, set up the network and other things to do.

Do you know that there’s a tool out there that will help you automate this painful process? Vagrant is the tool that you want.

Vagrant Logo

Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past. — Vagrant Intro

Their introduction stated that Vagrant will help you to build and manage VM automatically. How vagrant achieve this?

Communicate with VM provider API

Vagrant creates the VM for you by communicating with the API created by the VM provider such as VirtualBox and VMware. A provider is a program that creates the VM. Basically, vagrant itself does not create the VM, they just tell the provider to create the VM.

Tell the provider to create VM from ‘box’

Vagrant will tell the provider to create VM according to the box you specify in the configuration. The box here is like an image of the system you want in your VM. You can find publicly available boxes here or you can create your own boxes.

Run the provision script in the VM

After the provider creates the VM, Vagrant will run the provision script in your VM. Provision script is like a list of command you want to run in your VM. Provision script will help you reduce the time to manually run the script in your VM. Provision script can be written in many ways like a shell script, Ansible, or Chef. You can find more about provision here.

VM is ready

After the provisioning is completed then your VM is ready to use, you can SSH to your VM or do anything you want with it.

Vagrant flow

How to configure vagrant?

You can easily configure vagrant using the Vagrantfile which written in Ruby language. Many things can be configured within Vagrantfile, you can read more about Vagrantfile to find things to configure here.

Call to action: If you‘ve enjoyed this article, please do two things to help others find it: share it and recommend it 👏

--

--

William Albertus Dembo

Junior Site Reliability Engineer at GoJek — one of the biggest start-ups in Southeast Asia. I love to go hiking and explore new things.