Skip to main content

Creating a Basic Vagrantfile

Hands-On Lab

 

Photo of Elle Krout

Elle Krout

Content Team Lead in Content

Length

00:15:00

Difficulty

Beginner

Vagrant lets us define our desired development environment. It also leverages existing platforms such as VirtualBox and Docker to provision these environments based on how we define them. In this hands-on lab, we use Vagrant alongside LXC to create a simple Vagrantfile that provisions a single Debian host to our specifications.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating a Basic Vagrantfile

Introduction

In this hands-on lab, we use Vagrant alongside LXC to create a simple Vagrantfile that provisions a single Debian host to our specifications.

Solution

Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

ssh cloud_user@PUBLIC_IP_ADDRESS

Generate the Vagrantfile

  1. Create the wanderer-app directory:

    mkdir wanderer-app
  2. Move into that directory:

    cd wanderer-app/
  3. Generate a Vagrantfile:

    vagrant init

Write the Vagrantfile

  1. Open the Vagrantfile:

    vim Vagrantfile
  2. Update the Vagrantfile based on the instructions; you may wish to remove any unneeded contents generated in the vagrant init:

    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    Vagrant.configure("2") do |config|
     config.vm.box = "fgrehm/wheezy64-lxc"
     config.vm.box_version = "1.2.0"
     config.vm.hostname = "wanderer"
     config.vm.provider "lxc"
    end

Test the Vagrantfile

  1. To test the Vagrantfile, run:

    vagrant up
  2. Check whether the Vagrant box is running with:

    vagrant status

Conclusion

Congratulations - you've completed this hands-on lab!