This tutorial is out of date and no longer maintained.
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:
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
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/
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" end
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:
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" end This is generally caused by the OpenSSL configuration associated with the Ruby install being unaware of the system specific ca certs.
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.
The provider supports the following Vagrant sub-commands:
Many thanks to Shawn Dahlen for creating this plugin.
Vagrant—Article #3
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
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!
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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 1.8.3.4 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?
Thanks
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 anapi_key
as your DO credentials within Vagrantfile, uses DO’s depricated v1.X api. The current v2.X api uses a singletoken
.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?