This article is outdated and may not work correctly for current operating systems or software.
Vagrant is a tool used to create and configure lightweight, reproducible, and portable development environments. In this quick guide, we go through how to provision a machine with Vagrant on Vultr servers.
Note: This tutorial assumes you already have VirtualBox and Vagrant installed on your local machine.
Perform below actions from the terminal on your local machine:
Install Vagrant Vultr plugin vagrant plugin install vagrant-vultr
Create a directory to house a test project and cd into it mkdir test_project && cd test_project
Run vagrant init
- This creates a VagrantFile that will contain settings for provisioning server.
Open VagrantFile and replace the line config.vm.box = "base"
with below:
Note: Replace 'YOUR_TOKEN' below with your token from Vultr Admin -> Settings -> API
config.vm.provider :vultr do |vultr, override|
override.ssh.private_key_path = '~/.ssh/id_rsa'
override.vm.box = 'vultr'
override.vm.box_url = 'https://github.com/p0deje/vagrant-vultr/raw/master/box/vultr.box'
vultr.token = 'YOUR_TOKEN' #You can also use VULTR_TOKEN environment variable
vultr.region = 'Atlanta'
vultr.plan = '768 MB RAM,15 GB SSD,1.00 TB BW'
vultr.os = 'Ubuntu 14.04 x64'
end
vagrant up --provider=vultr
and watch a new 768 MB RAM,15 GB SSD instance spin up on your Vultr account.Vultr API documentation is your friend... you'll find endpoints that reveal information on proper values to use for settings like region, plan and os here.
For small projects, you will likely have a setting closer to below in your Vagrant file so that running vagrant up loc
provisions your environment locally and running vagrant up prod --provider=vultr
provisions the same machine on Vultr.
config.vm.define :loc do |loc_config|
loc_config.vm.box = 'bento/ubuntu-14.04'
loc_config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", 768]
vb.customize ["modifyvm", :id, "--cpus", 1]
end
loc_config.vm.provision "shell", inline: "echo 'export ENV=loc' >> ~/.profile", run: "always"
loc_config.vm.provision "shell", path: "./provision.sh"
end
config.vm.define :prod, autostart: false, primary: false do |prod_config|
prod_config.vm.provider :vultr do |vultr, override|
override.ssh.private_key_path = '~/.ssh/id_rsa'
override.vm.box = 'vultr'
override.vm.box_url = "https://github.com/p0deje/vagrant-vultr/raw/master/box/vultr.box"
vultr.token = 'YOUR_TOKEN' #You can also use VULTR_TOKEN environment variable
vultr.region = 'Atlanta'
vultr.plan = '768 MB RAM,15 GB SSD,1.00 TB BW'
vultr.os = 'Ubuntu 14.04 x64'
end
prod_config.vm.provision "shell", inline: "echo 'export ENV=prod' >> ~/.profile", run: "always"
prod_config.vm.provision "shell", path: "./provision.sh"
end
Vagrant is a tool that greatly reduces the time it takes to provision servers locally (or on your Vultr cloud instance). It can be used to very quickly setup test and staging environments on your Vultr's cloud account.