How To Use DigitalOcean as Your Provider in Vagrant on an Ubuntu 12.10 VPS

Published on August 1, 2013
How To Use DigitalOcean as Your Provider in Vagrant on an Ubuntu 12.10 VPS

This tutorial is out of date and no longer maintained.

About Vagrant

Vagrant is a powerful open source software for configuring and deploying multiple development environments. It is designed to work on Linux, Mac OS X, or Windows and although it comes with VirtualBox for the virtualization needs, it can be used also with other providers such as VMware or AWS.

In this tutorial, we will set up Vagrant to use DigitalOcean as a provider. This means that you will be able to use DO droplets (VPS) as development machines to deploy from Vagrant. The tutorial assumes you have already installed Vagrant on your environment and it is recommended you consult two previous articles about Vagrant:

  1. How to Install Vagrant on a VPS Running Ubuntu 12.04
  2. How to Use Vagrant on Your Own VPS Running Ubuntu

Installing the DigitalOcean: Vagrant Integration Plugin

To install the plugin, you have to follow two quick steps. First, run the command of installing the plugin:

vagrant plugin install vagrant-digitalocean

Followed by the command to add the new box to Vagrant (remember what boxes are from the previous articles?):

vagrant box add digital_ocean https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box

Configuring a Project to Run with this Provider

In order to use this plugin, you’ll need some form of letting Vagrant communicate with DigitalOcean. This is why the API is there, and why you now have to log into your DigitalOcean account and generate a new API key for authentication. Navigate to https://www.digitalocean.com/api_access and click Create to generate your new API key. You'll use this in the configuration together with your client ID seen above it.

Now that you have installed the plugin, added the DO specific box, and you have your API key ready. Let’s create a project that will use them. In the previous articles we’ve been working with a project to illustrate how Vagrant works with its default provider: VirtualBox. Let’s now create another project for DigitalOcean cloud server. Create a root directory for it (outside of the previous project folder) and navigate in it:

mkdir test_project2
cd test_project2

Next, run the initialization command:

vagrant init

This will create the required Vagrantfile.

Before we edit this file, let’s create the SSH keys needed for authentication with DigitalOcean. Run the following command to generate your SSH key pair:

ssh-keygen -t rsa

You can accept the defaults by pressing enter. This will place the SSH private and public keys to the path we will specify below in the Vagrantfile configuration. For more information about generating SSH key, check out this tutorial. Now let’s edit the Vagrantfile and configure it:

nano Vagrantfile

Find the following line:

config.vm.box = "base"

And replace it with:

config.vm.box = "digital_ocean"

Below it, add the following lines:

config.ssh.private_key_path = "~/.ssh/id_rsa"
config.vm.provider :digital_ocean do |provider|
    provider.client_id = "YOUR CLIENT ID"
    provider.api_key = "YOUR API KEY"
    provider.image = "Ubuntu 12.10 x64"
    provider.region = "New York 2"

With the first line, you are specifying the path to the SSH private key file. This means that the provider will create a new DigitalOcean SSH key using your public key which is at that path with a .pub extension (the one you created earlier). The next two lines are for the DO API, so make sure you replace where needed with your client ID and the API key. With the image, you specify what type of cloud server you want deployed whereas with the region you choose the DigitalOcean data center you’d like the droplet to be created in. To see the available options, check the DO droplet creation page.

You can add some additional settings in the vm.provider block:

  • provider.size: A string representing the size to use when creating a new VPS (e.g. 1GB). Currently, it defaults to 512MB.
  • provider.ssh_key_name: A string representing the name to use when creating a DigitalOcean SSH key for VPS authentication. It defaults to Vagrant.

Save the file and exit. Now you can run the vagrant up command specifying the DigitalOcean provider to deploy your new VPS:

vagrant up --provider=digital_ocean

If you get the following error:

The secure connection to the DigitalOcean API has failed. Please
ensure that your local certificates directory is defined in the
provider config.

    config.vm.provider :digital_ocean do |vm|
      vm.ca_path = "/path/to/ssl/ca/cert.crt"

This is generally caused by the OpenSSL configuration associated
with the Ruby install being unaware of the system specific ca

It means you are missing the root certificates necessary to communicate with DigitalOcean. To fix it, open the .bashrc file:

nano ~/.bashrc

And add the following line at the bottom:

export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

Save the file and exit. Open again the Vagrantfile and add the following line below the one in which you specified the region (the order is not so important but it has to be part of the vm.provider block):

provider.ca_path = "/etc/ssl/certs/ca-certificates.crt"

Save the file and exit. Now try again to deploy the VPS:

vagrant up --provider=digital_ocean

Now a droplet should be created in your account, in the specified region and using the image you wanted. You can check it out in your DO account. You can use that basically as you would have used a VirtualBox guest machine.

Supported Commands

The provider supports the following Vagrant sub-commands:

  • vagrant destroy: Destroys the droplet instance.
  • vagrant ssh: Logs into the droplet instance using the configured user account.
  • vagrant halt: Powers off the droplet instance.
  • vagrant provision: Runs the configured provisioners and rsyncs any specified config.vm.synced_folder.
  • vagrant reload: Reboots the droplet instance.
  • vagrant rebuild: Destroys the droplet instance and recreates it with the same IP address is was assigned to previously.
  • vagrant status: Outputs the status (active, off, not created) for the droplet instance.

Many thanks to Shawn Dahlen for creating this plugin.

Vagrant—Article #1

Vagrant—Article #2

Vagrant—Article #3

Article Submitted by: Danny

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

This Vagrant: https://github.com/10up/varying-vagrant-vagrants

deploys, in my mind, an ideal wordpress environment to my local OS X Machine

I have successfully used and deployed a droplet with your digital ocean vagrant api as a tester.

However I would like deploy the same setup I have my local machine that was made with the above Vagrant config.

What method do I use to achieve this? Is it the same vagrant as “10up’s” If so how do vagrant up this to a droplet on digital ocean.

This what 10up VVV give me locally - I would very much like to have the same environment as a droplet: (hopefully using Vagrant)

Ubuntu 12.04 LTS (Precise Pangolin) WordPress Develop WordPress Stable WordPress Trunk WP-CLI nginx 1.4.2 mysql 5.5.32 php-fpm 5.4.17 memcached 1.4.13 PHP memcache extension 3.0.8 xdebug 2.2.3 PHPUnit 3.7.24 ack-grep 2.04 git subversion 1.7.9 ngrep dos2unix Composer phpMemcachedAdmin 1.2.2 BETA phpMyAdmin 4.0.5 Webgrind 1.1 NodeJs Current Stable Version grunt-cli Current Stable Version

Many thanks Shane

The link To see the available options, check the DO droplet creation page is broken.

Followed the steps abovee but can’t seem to get it working:

root@CENTCOM:~# vagrant up --provider=digital_ocean The provider ‘digital_ocean’ could not be found, but was requested to back the machine ‘default’. Please use a provider that exists.

Is this tutorial up-to-date? Seeing several questionable things (e.g. no create button at https://developers.digitalocean.com/)

Would you recommend to use this for a production VPS?


Hi, сan I deploy this environment (Vagrantfile), using digital ocean vagrant api ???

On the local machine I deploy this environment without problems, using and Vagrant and VM VirtualBox

What method do I use to achieve this (deploy to DO)?

Look here (under configure) for a better example of what to put in the Vagrantfile: https://github.com/smdahlen/vagrant-digitalocean

This appears to be very out of date - I’m attempting to setup a Mezzanine project, and the url for API access has changed, and the instructions do not provide enough information to fill out the form on the current API page.

Is there any chance that a fresh, up -to-date guide to deploying a Mezzanine project is about to be published?

Worth noting: Refer to the instructions directly in the vagrant-digitalocean plugin. The example, particularly when setting both a client_id and an api_key as your DO credentials within Vagrantfile, uses DO’s depricated v1.X api. The current v2.X api uses a single token.

Key fix worked, thanks!

Next problem, after running vagrant up, I get…

*Contained no object with the value “Ubuntu 14.04 x64” for the the key “name”.

Please ensure that the configured value exists in the collection.*

Does the box have to exist? Or does it get created?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel