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!
The link : Using Vagrant on Your Own VPS Running Ubuntu is broken
Thanks-- I’ll fix that now!
Or use puphpet :) Been using it lately to setup new dev servers at work and it’s very handy
Very cool in deed
If anyone is looking for a decent Vagrant image to get this up and running with, you can check out my Vagrant dev machine at https://github.com/bacongobbler/bacongobbler-vagrant-vm. You should just need to add the docs that are listed in this post, along with installing the plugins listed in the README. Let me know if you run into issues with this. :)
Note that if you installed Vagrant on Windows to c:\Program Files\Vagrant the space in the folder name will kill the vagrant-digitalocean plugin install. Error looks like:
$ vagrant plugin install vagrant-digitalocean Installing the ‘vagrant-digitalocean’ plugin. This can take a few minutes… C:/Program Files/Vagrant/embedded/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:556:in `rescue in block in build_extensions’: ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError) “C:/Program Files/Vagrant/embedded/bin/ruby.exe” extconf.rb creating Makefile
make generating generator-i386-mingw32.def /bin/sh: C:/Program: No such file or directory make: *** [generator-i386-mingw32.def] Error 127 … (stack trace)
(I’m not sure whether to hate filenames with spaces or programs that can’t handle spaces in filenames…)
On Mac OS I can’t find the cert.crt location… does anyone know where is it?
/etc/ssl/certs/ca-certificates.crt looks like for linux only…
Thanks
@nik.mda: <pre>You can generate the file you need by opening Keychain Access (from /Applications/Utilities), going to the System Roots keychain, selecting everything and then choosing Export Items… from the File menu. Make sure the File Format is set to Privacy Enhanced Mail (.pem), then save it to your Desktop as Certificates. Next, in Terminal enter</pre> http://mercurial.selenic.com/wiki/CACertificates
Once you do that, the ca-certificates.crt mac equivalent would be stored as ~/Desktop/Certificates.pem
I haven’t tried it as I do not have access to a machine running OSX but let me know if that works :]
Those instructions seems a bit more clear: https://github.com/smdahlen/vagrant-digitalocean#install
will follow and will let you know. Thanks Kamal!
So you do this
brew install curl-ca-bundle
then you set the path in Vagrantfile and ~/.bashrc to/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt
and it worked.