Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hooking around provisioners runs #2405

Merged
merged 3 commits into from
Nov 25, 2013

Conversation

fgrehm
Copy link
Contributor

@fgrehm fgrehm commented Oct 21, 2013

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 fgrehm/vagrant-notify#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 but targeting multiple providers

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

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

@mitchellh
Copy link
Contributor

This is a great idea. I'm going to modify it slightly but merge this. I'll CC You on the modification, and might just blow your mind.

mitchellh added a commit that referenced this pull request Nov 25, 2013
core: support hooking around provisioners runs
@mitchellh mitchellh merged commit d6fb083 into hashicorp:master Nov 25, 2013
@fgrehm fgrehm deleted the 2044-provisioner-hooking branch November 25, 2013 16:04
@fgrehm fgrehm mentioned this pull request Dec 3, 2013
@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants