Use Vagrant to Spin Up Linux VMs

Vagrant I’m not an expert on Vagrant. I’ve literally used it once, but it’s pretty cool.

Here’s how I used Vagrant.

I needed to create a Linux VM that I could thrash on, throw in the garbage, recreate it and trash some more. I was developing an Ansible deployment.

This tutorial assumes to things

  1. Vagrant installed.
  2. VirtualBox installed.

If either of those two things is not true, you should make them true before continuing. If you don’t, what’s the point, right?

Create two files, one called Vagrant and another called inventory

I’ll assume you created a directory called “vagrant,” but it doesn’t matter what you call it, or if you use a special directory or not.

In the vagrant directory, create two files. You don’t actually have to do this. I’m just doing it to be verbose.

mkdir vagrant;cd vagrant;touch Vagrant;touch inventory

Vagrant Config

Edit Vagrant and make it look like this.

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|

  # Configure Linux VM = "geerlingguy/centos7"
  config.ssh.insert_key = false
  config.vm.synced_folder '.', '/vagrant', disabled: true

  # Create VirtualBox Linux VM
  config.vm.provider :virtualbox do |v|
    v.memory = 512
    v.cpus = 1
    v.linked_clone = true
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.customize ["modifyvm", :id, "--ioapic", "on"]

  # Apache.
  config.vm.define "apache" do |apache|    
    apache.vm.provision "shell",
      inline: "sudo yum update -y"
    apache.vm.provider :virtualbox do |v|
      v.customize ["modifyvm", :id, "--memory", 256]

Now edit inventory so it looks like this.



Build It

Now run Vagrant to build out the Linux VM in VirtualBox.

vangrant up


After the VM is up, I then run my Ansible playbook on it to build out my application envrionment.

Share Button