Skip to content

Commit

Permalink
Merge pull request #2405 from fgrehm/2044-provisioner-hooking
Browse files Browse the repository at this point in the history
core: support hooking around provisioners runs
  • Loading branch information
mitchellh committed Nov 25, 2013
2 parents 8d99382 + a5c15fd commit d6fb083
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/vagrant/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Builtin
autoload :Lock, "vagrant/action/builtin/lock"
autoload :Provision, "vagrant/action/builtin/provision"
autoload :ProvisionerCleanup, "vagrant/action/builtin/provisioner_cleanup"
autoload :ProvisionerRun, "vagrant/action/builtin/provisioner_run"
autoload :SetHostname, "vagrant/action/builtin/set_hostname"
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
autoload :SSHRun, "vagrant/action/builtin/ssh_run"
Expand Down
16 changes: 15 additions & 1 deletion lib/vagrant/action/builtin/provision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,21 @@ def run_provisioner(env, name, p)
env[:ui].info(I18n.t("vagrant.actions.vm.provision.beginning",
:provisioner => name))

p.provision
callable = Builder.new.tap { |b| b.use ProvisionerRun, p }
action_runner.run(callable,
:action_name => :provisioner_run,
:provider_name => name
)
end

def action_runner
@action_runner ||= Action::Runner.new do
{
:env => @env[:env],
:machine => @env[:machine],
:ui => @env[:ui]
}
end
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions lib/vagrant/action/builtin/provisioner_run.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "log4r"

module Vagrant
module Action
module Builtin
# This action is basically a wrapper on top of provisioner runs that
# enable plugins to hook around the provisioning itself
class ProvisionerRun
def initialize(app, env, provisioner)
@app = app
@provisioner = provisioner
end

def call(env)
@app.call(env)
@provisioner.provision
end
end
end
end
end

0 comments on commit d6fb083

Please sign in to comment.