diff --git a/lib/vagrant/action/runner.rb b/lib/vagrant/action/runner.rb index b92d2726c..b2306e12a 100644 --- a/lib/vagrant/action/runner.rb +++ b/lib/vagrant/action/runner.rb @@ -27,6 +27,19 @@ module Vagrant environment.merge!(@lazy_globals.call) if @lazy_globals environment.merge!(options || {}) + # Setup the action hooks + hooks = Vagrant.plugin("2").manager.action_hooks + if !hooks.empty? + @logger.info("Preparing hooks for middleware sequence...") + env[:action_hooks] = hooks.map do |hook_proc| + Hook.new.tap do |h| + hook_proc.call(h) + end + end + + @logger.info("#{env[:action_hooks].length} hooks defined.") + end + # Run the action chain in a busy block, marking the environment as # interrupted if a SIGINT occurs, and exiting cleanly once the # chain has been run. diff --git a/lib/vagrant/plugin/v2/manager.rb b/lib/vagrant/plugin/v2/manager.rb index 2a743c59d..f8ae7c940 100644 --- a/lib/vagrant/plugin/v2/manager.rb +++ b/lib/vagrant/plugin/v2/manager.rb @@ -14,6 +14,17 @@ module Vagrant @registered = [] end + # This returns all the action hooks. + # + # @return [Array] + def action_hooks + [].tap do |result| + @registered.each do |plugin| + result += plugin.components.action_hooks + end + end + end + # This returns all the registered commands. # # @return [Hash]