Report this

What is the reason for this report?

Is there a way to use vagrant to spin up multiple droplets?

Posted on April 16, 2015

I understand that you can use Vagrant to spawn a droplet and do configuration and installation, but what I want to know is if I can use vagrant to spawn multiple droplets without having to have duplicated vagrant projects?



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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

With Vagrant, each folder and Vagrantfile represents a separate project. If you want to launch multiple copies of the same setup, you’ll need to duplicate the project. If your project needs multiple droplets (e.g. separate web and database servers), you can use a Vagrant multi-machine environment. For instance, this would create two different droplets, one named “db” and one named “web.”

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = 'digital_ocean'
  config.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box"
  config.ssh.private_key_path = '/path/to/id_rsa'

  config.vm.define "db" do |db|
    config.vm.provider :digital_ocean do |provider|
      provider.token = 'YOUR_DO_TOKEN'
      provider.image = 'ubuntu-14-04-x64'
      provider.region = 'nyc3'
      provider.size = '512mb'
      provider.ssh_key_name = 'key_name'
    end
  end

  config.vm.define "web" do |web|
    config.vm.provider :digital_ocean do |provider|
      provider.token = 'YOUR_DO_TOKEN'
      provider.image = 'ubuntu-14-04-x64'
      provider.region = 'nyc3'
      provider.size = '512mb'
      provider.ssh_key_name = 'key_name'
    end
  end

end

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.