I need to run several boxes with Vagrant.
Is there a way to do that?
These don't relate one to another in any way, they can be thought as different environments using for test so it seems that multi-machine setup has nothing to do with this.
You can either use so called multi-machine environment to manage these boxes together in one project/Vagrantfile. They don't necessarily have to be somehow connected, ease of management may be the reason alone, e.g. if you need to start them up at the same time.
Vagrant.configure("2") do |config| # ... end. The "2" in the first line above represents the version of the configuration object config that will be used for configuration for that block (the section between the do and the end ). This object can be very different from version to version.
The best way is to use an array of hashes. You can define the array like:
servers=[ { :hostname => "web", :ip => "192.168.100.10", :box => "saucy", :ram => 1024, :cpu => 2 }, { :hostname => "db", :ip => "192.168.100.11", :box => "saucy", :ram => 2048, :cpu => 4 } ]
Then you just iterate each item in server array and define the configs:
Vagrant.configure(2) do |config| servers.each do |machine| config.vm.define machine[:hostname] do |node| node.vm.box = machine[:box] node.vm.hostname = machine[:hostname] node.vm.network "private_network", ip: machine[:ip] node.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--memory", machine[:ram]] end end end end
You can definitely run multiple Vagrant boxes concurrently, as long as their configuration does not clash with one another in some breaking way, e.g. mapping the same network ports on the host, or using same box names/IDs inside the same provider. There's no difference from having multiple boxes running on a provider manually, say multiple boxes on VirtualBox, or having them registered and started up by Vagrant. The result is the same, Vagrant just streamlines the process.
You can either use so called multi-machine environment to manage these boxes together in one project/Vagrantfile. They don't necessarily have to be somehow connected, ease of management may be the reason alone, e.g. if you need to start them up at the same time.
Or you can use separate projects/Vagrantfiles and manage the machines from their respective directories, completely separated.
In case of running multiple instances of the same project, you need multiple copies of the project directory, as Vagrant stores the box state in the .vagrant
directory under the project.
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