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

Trigger before :provision is not called during first up. #45

Closed breuerss closed 9 years ago

breuerss commented 9 years ago

The following Vagrantfile does not create the expected tmp/file.txt in the working directory on first startup using version 0.5.0.

if !Vagrant.has_plugin?("vagrant-triggers")
    puts "'vagrant-triggers' plugin is required"
    puts "This can be installed by running:"
    puts
    puts " vagrant plugin install vagrant-triggers"
    puts
    exit
end

Vagrant.configure(2) do |config|
    config.trigger.before :provision do
        info "Creating temporary file"

        run "mkdir -p tmp"
        run 'touch tmp/file.txt'
    end

    config.vm.define "Device" do |device|
        device.vm.box = "ubuntu/trusty64"
    end
end

Best regards

emyl commented 9 years ago

Hi!

This is expected, since config.trigger.before :provision is supposed to fire the trigger only before the vagrant provision command.

For your use case, using the built-in provisioner should be a perfect fit:

Vagrant.configure("2") do |config|
  # Your existing Vagrant configuration
  ...

  config.vm.provision "trigger", :option => "value" do |trigger|
    trigger.fire do
      run "script"
    end
  end
end