mitchellh/vagrant — pull request #2405 by fgrehm (2013-10-21 23:05:30+00:00)
Title: core: Support hooking around provisioners runs

This PR implements GH-2044 and although I wasn't able to spike on changing vagrant-cachier code to remove the monkey patches we have in place, I wanted to open this up for discussion / code review as I was able to spot 2 other use cases for it :)

Apart from using it on vagrant-cachier, I want to use this feature to finally support https://github.com/fgrehm/vagrant-notify/issues/5 and another use case would be a plugin that keeps track of the time taken on each provisioner run and reports back to the user, something like [vagrant-aws's TimedProvision](https://github.com/mitchellh/vagrant-aws/blob/master/lib/vagrant-aws/action/timed_provision.rb) but targeting multiple providers

To try this out, you can use the following Vagrantfile using this branch:

```ruby
class Action
def initialize(app, env)
@app = app
end

def call(env)
puts 'before'
puts "name: #{env[:provider_name]}"
@app.call env
puts 'after'
end
end

class Plugin < Vagrant.plugin('2')
name 'testing'
action_hook 'hook-name', :provisioner_run do |hook|
hook.before Vagrant::Action::Builtin::ProvisionerRun, Action
end
end

Vagrant.configure("2") do |config|
config.vm.box = "some-box"
config.vm.provision :shell, inline: 'echo hello'
config.vm.provision :shell, inline: 'echo hello 2'
end
```