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

run script in between commands in a multi-machine environment #31

Closed uchagani closed 9 years ago

uchagani commented 9 years ago

Does this plugin handle the situation where, in a multi-machine environment, if I bring up 2 machines with vagrant up, i can execute commands in between bringing the two machines up?

For example: Assuming a 2 machine setup when vagrant up is executed:

execute script machine 1 starts up execute script machine 2 starts up

emyl commented 9 years ago

Hello,

Yes. Just ensure to disable parallel execution if your provider supports it. Here is an example:

config.trigger.before :up, :stdout => true, :vm => ["vm1", "vm2"] do
  info "Hello world!"
end
vagrant@precise64:/vagrant/vagrant-triggers$ bundle exec vagrant up --no-parallel      
Bringing machine 'vm1' up with 'lxc' provider...                                       
Bringing machine 'vm2' up with 'lxc' provider...                                       
==> vm1: Running triggers before up...                                                 
==> vm1: Hello world!                                                                  
==> vm1: Setting up mount entries for shared folders...                                
    vm1: /vagrant => /vagrant/vagrant-triggers                                         
==> vm1: Starting container...                                                         
==> vm1: Waiting for machine to boot. This may take a few minutes...                   
    vm1: SSH address: 10.0.3.165:22                                                    
    vm1: SSH username: vagrant                                                         
    vm1: SSH auth method: private key                                                  
==> vm1: Machine booted and ready!                                                     
==> vm1: Machine already provisioned. Run `vagrant provision` or use the `--provision` 
==> vm1: to force provisioning. Provisioners marked to run always will still run.      
==> vm2: Running triggers before up...                                                 
==> vm2: Hello world!                                                                  
==> vm2: Setting up mount entries for shared folders...                                
    vm2: /vagrant => /vagrant/vagrant-triggers                                         
==> vm2: Starting container...                                                         
==> vm2: Waiting for machine to boot. This may take a few minutes...                   
    vm2: SSH address: 10.0.3.220:22                                                    
    vm2: SSH username: vagrant                                                         
    vm2: SSH auth method: private key                                                  
==> vm2: Machine booted and ready!                                                     
==> vm2: Machine already provisioned. Run `vagrant provision` or use the `--provision` 
==> vm2: to force provisioning. Provisioners marked to run always will still run.