Building more complex lab with Vagrant

You can easily setup a bigger environment with a number of virtual machines using Vagrant. This helps if you want to test various more complex scenarios (high-availabilities, failures, replications, etc.) locally.

Once you're done with you virtual machine setup, package your Vagrant box:

vagrant package --output centos.box

Then, you can add your packaged box to the vagrant:

vagrant box add centos.box --name centos

Just to double-check if the box has been added to vagrant, list all added boxes:

vagrant box list

Edit Vagrant file to add the following lines (this configuration is for 3 replicated servers):

def config_centos(config, node_number)
config.vm.define "zipset#{node_number}" do |replica|
    replica.vm.box = "centos"
    replica.vm.hostname = "centos#{node_number}"
    replica.vm.network "private_network", ip: "192.168.50.10#{node_number}"
    end

    for node_number in 1..3
        config_centos config, node_number
    end

Now we can start all three servers at once with the following Vagrant command:

vagrant up /centos*/

You can check all of your Vagrant machines statuses with vagrant global-status command.