Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Vagrant trigger to execute bash script on host

I use Vagrant to start my testing environment. Sadly I have to retrieve information (passwords) before spinning up my Vagrant box. So far I use Vagrant-Triggers to do this and have multiple run "do something" commands.

IS

[:up, :provision].each do |cmd|
    config.trigger.before cmd, stdout: true do
      run "rm -rf #{cookbooks_path}"
      run "mkdir -p #{cookbooks_path}"
      run "touch fileX"
      run "touch fileY"
      run "touch fileZ"
    end
end

How can I move all my commands to one batch file which I then only include?

SHOULD

[:up, :provision].each do |cmd|
    config.trigger.before cmd, stdout: true do
      include_script "Vagrant_trigger_before.sh"
    end
end

Thank you for your help!

like image 224
lony Avatar asked Jan 05 '17 10:01

lony


2 Answers

You can run your script directly using the run instructions

[:up, :provision].each do |cmd|
    config.trigger.before cmd, stdout: true do
      run "Vagrant_trigger_before.sh"
    end
end
like image 176
Frederic Henri Avatar answered Sep 23 '22 13:09

Frederic Henri


After trigger plugin was merged to vagrant mainline, the syntax seems to be changed to

config.trigger.before :up, :provision do |trigger|
  trigger.run = {inline: "Vagrant_trigger_before.sh"}
end

Ref: https://www.vagrantup.com/docs/triggers/configuration#inline

like image 33
Lin_n Avatar answered Sep 23 '22 13:09

Lin_n