I have a multi-machine Vagrantfile setting up a 5 node environment.
I've been looking around to see what levels of control you have over the order of provisioning, but it's pretty limited:
https://docs.vagrantup.com/v2/multi-machine/
I want to provision 5 nodes, then go back to the first node, and run other provisioning steps there.
What I mean is that you have a Vagrantfile like this:
Vagrant.configure('2') do |config|
config.vm.provision some stuff
config.vm.define 'node1' do |node1|
node1.vm.provision some more stuff
end
config.vm.define 'node2' do |node2|
node2.vm.provision some other stuff
end
... node3 node4 node 5 ...
end
But after vagrant has finished starting and provisioning the all the machines up to node5, I then want to run another provisioner on node1. Does anyone know how to do this? Maybe some ruby hackery?
Vagrant is able to define and control multiple guest machines per Vagrantfile. This is known as a "multi-machine" environment. These machines are generally able to work together or are somehow associated with each other.
Using the multi-machine feature of Vagrant, these environments can be modeled in the context of a single Vagrant environment without losing any of the benefits of Vagrant. Multiple machines are defined within the same project Vagrantfile using the config.vm.define method call.
Thought the article, you can use Vagrant create multiple VMs loops as above. I hope will this your helpful. Thank you for reading the DevopsRoles page! My name is Huu.
That is because the ordering is outside-in, in the order of the file. If you want to apply a slightly different configuration to multiple machines, see this tip. The moment more than one machine is defined within a Vagrantfile, the usage of the various vagrant commands changes slightly.
If what you want is to have that other provisioner to run automagically right after all the machines have been vagrant up
ed, unfortunately there's no way to do that as far as I know, Vagrant will allways run all the provisioners specified (unless you tell it to run just a subset of them).
The only way you might be able to emulate would be having different kinds of provisioners for each machine and selectively running them as needed. So, for example, you'd vagrant up --provision --provision-with=shell
and then run a vagrant provision --provision-with chef_solo
to have the shell provisioners run first and the chef_solo provisioning afterwards
But, if you want to manually fire up a provisioner after all the machines have been brought up you can just use the vagrant provision
command to accomplish that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With