emyl / vagrant-triggers

Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.
MIT License
546 stars 35 forks source link

Allow calling a proc when an action is triggered #7

Closed kjkuan closed 10 years ago

kjkuan commented 10 years ago

Hi, a total newbie here, but I wish something like this existed. Not sure if it's the best way to go, so feel free to do it in a different way and ignore this pull request.

Thanks

emyl commented 10 years ago

Hi,

I'm not sure that exposing the Vagrant environment in the Vagrantfile would be a wise thing, as it could lead to security problems.

As an example, the following statement:

config.trigger.before :up do |env|
  env[:machine].id = nil
end

Would probably make the Vagrant machine orphan.

Do you have a specific use case for your request? If so, please elaborate it more, I'll be happy to look for a possible solution.

kjkuan commented 10 years ago

Hi, Thanks for taking a look! Basically, my use case is that my script needs to be able to show text outputs and read user inputs so it can prompt the user and make decisions base on user inputs. I figured I can use Vagrant's ui object to do so, that's why I needed this feature.

About security..., I'm not sure if your example is a security problem or a configuration problem. To me, a Vagrantfile, or the vagrant-trigger plugin, already allows you to execute arbitrary code on your behalf, so I don't think passing @env to the callback will be a big deal. However, I admit that for my use case that I only need the ui object, so I can also live with passing just ui to the callback. :)

emyl commented 10 years ago

OK, got your idea. I already had something similar in mind for version 0.3 of the plugin, among other new features.

Something will happen in the next two/three weeks, stay tuned :wink: