Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Created April 20, 2012 05:21
Show Gist options
  • Save mitchellh/2426262 to your computer and use it in GitHub Desktop.
Save mitchellh/2426262 to your computer and use it in GitHub Desktop.

Making Plugins Easier in Vagrant

Vagrant plugins currently expose the FULL POWER of Vagrant. Unfortunately, as is often the case, "full power" means "complicated" (relatively), especially for those not familiar with Ruby.

Instead, I'd like to introduce an alternative "simple" API to plugins as well that people can confidently use. Below are some examples of this. I'm not even going to describe what each plugin does because it should be simple enough from the code, that's how simple they are!

The end goal is that it should be much more common to see Vagrant projects ship with custom commands like vagrant run-tests or vagrant start-server, to perform common tasks that previously required SSH.

These "easy" plugins can't do everything but they will be able to do the common things. If you want more power, full (non-easy) plugins should be used.

class SimpleHook < Vagrant.plugin("1")
  name "simple-hook"

  easy_hook :after, :setup_shared_folders do |action|
    action.vboxmanage(["modifyvm", :id, "foo", "bar"])
  end
end
class PipInstall < Vagrant.plugin("1")
  name "pip-install"

  easy_command "pip-install" do |action|
    action.run("cd /vagrant && pip install -r requirements.txt")
  end
end
class SubcommandExample < Vagrant.plugin("1")
  name "subcommands example"

  easy_command "web start" do |action|
    action.run("/etc/init.d/nginx start")
  end

  easy_command "web stop" do |action|
    action.run("/etc/init.d/nginx stop")
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment