Monthly Archives: March 2017

How I got Vagrant and Ansible running with a DigitalOcean provider

I’ve set up enough virtual servers and virtual machines by hand; it’s time to automate! I found this very clearly written tutorial and followed it almost exactly. It gave me a VM running on Virtualbox, set up by Vagrant and provisioned by Ansible, from a laptop running Arch Linux.

Vagrant and Ansible on virtualbox

I made three changes to the Vagrantfile for virtualbox. Two changes were for customization and one was to fix a problem.

  • I wanted to use Debian 8, so I set the box to “debian/jessie64”.
  • I named the VM “vbox-sys3”.
  • Without the vb.customize fix, the VM could not resolve DNS. See DNS error.

Actually, I made four changes. The Ansible playbook is “../playbook.yml” instead of “playbook.yml” because I moved the Vagrantfiles down one level, so both the virtualbox and the Digital Ocean files can use the same playbook. Although I’ve also changed the playbook, you can use the playbook exactly from the tutorial and have it work.

Vagrant.configure("2") do |config| = "debian/jessie64"

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] = "vbox-sys3"
  end "forwarded_port", guest: 80, host: 14280

  config.vm.provision :ansible do |ansible|
    ansible.playbook = "../playbook.yml"

Vagrant and Ansible on Digital Ocean

To get things running on Digital Ocean, I followed the example in the github site for the digitalocean Vagrant plugin, with three changes:

  • An enviromental variable for the API token.

    I use “DIGITALOCEAN_TOKEN”, and set it during my shell initialization.

  • Debian 8 for the image.

    The image name for this turned out to be “debian-8-x64”. See DO images.

  • Only one droplet.

    The example had two.

  • I disabled NFS functionality.

    See NFS error.

Vagrant.configure('2') do |config|

  config.vm.define "system3" do |config|
      config.vm.provider :digital_ocean do |provider, override|
        override.nfs.functional = false
        override.ssh.username = 'vagrant'
        override.ssh.private_key_path = '~/.ssh/id_rsa' = 'digital_ocean'
        override.vm.box_url = ""
        provider.token = ENV['DIGITALOCEAN_TOKEN']
        provider.image = 'debian-8-x64'
        provider.region = 'sfo1'
        provider.size = '512mb'

      end "forwarded_port", guest: 80, host: 14280

      config.vm.provision :ansible do |ansible|
        ansible.playbook = "playbook.yml"


Some problems I ran into:

Got DNS error on virtualbox

This question on Server Fault gave me the answer to this problem. I had to make the following change to get DNS working on the VM.

config.vm.provider :virtualbox do |vb|
  vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]

Wnat images are available for Digital Ocean?

The list isn’t on the website; you have to query the API. A convenient way to to this is to use Vagrant:

vagrant digitalocean-list images ${DIGITALOCEAN_TOKEN}

Got “SSH authentication failed” error on Digital Ocean

I was gettting the following error:

 INFO ssh: SSH not up: #<Vagrant::Errors::SSHAuthenticationFailed: SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.>

And the keypair was, in fact, not properly set up. The proper setup requires that the public key part of ‘override.ssh.private_key_path’, above, be one of the ssh keys that Digital Ocean knows about, as described here.

With these configurations, I can now spin up (almost) the same machine locally and on Digital Ocean.

Got errors relating to NFS.

The installation stopped with the following error:

No host IP was given to the Vagrant core NFS helper. This is an
internal error that should be reported as a bug.

This was reported a couple of times in the vagrant-digitalocean issues, which have all been closed. One of the workarounds suggested was to disable NFS, which is what I did.