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 provision trigger only if provisioning succeded #24

Closed alexandru-calinoiu closed 9 years ago

alexandru-calinoiu commented 9 years ago

Is there a way to run the provision trigger only if the provisioning succeded?

snowch commented 9 years ago

I would like to add to this:

Is there a way to run the provision trigger only if the provisioning succeeded on all vms in a multivm environment?

emyl commented 9 years ago

This should work starting from version 0.5.0, using the new provisioner-like syntax:

config.vm.provision "trigger", :option => "value" do |trigger|
  trigger.fire do
    run "script"
  end
end
snowch commented 9 years ago

Hi Emyl,

Thanks for implementing this. Would you be able to clarify how I could automatically execute some script after provisioning was successful for all VMs in a multi-VM environment?

An extract from my Vagrantconfig is below:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  ...
  # setup loadbalancer node(s)
  0.upto($lb_ip_offset) do |num|
    config.vm.define "lb#{num}" do |lb|
      lb.vm.network :private_network ...
      lb.vm.hostname = "lb#{num}.#{$domain_name}"
      lb.vm.box = $os_string
      lb.vm.provision "shell", path: "scripts/install_lb_node.sh", args: "#{num} \"#{$os_repo_install_cmd}\""
    end
  end

  # setup the database nodes
  1.upto($db_node_count) do |num|
    config.vm.define "node#{num}" do |node|
      node.vm.network :private_network ...
      node.vm.hostname = "node#{num}.#{$domain_name}"
      node.vm.box = $os_string
      node.vm.provision "shell", path: "scripts/install_db_node.sh", args: "#{num} #{cookie} \"#{$os_repo_install_cmd}\""
    end
  end
  ...
  # how to run a script after all vms have been successfully provisioned?
end