Today I will just share with you piece of code that I quite often used when I was working with quick spin of machines using Vagrant. It will create 2 VMs for you based on your requirements ( can be more if you modify the code 🙂 )
# based on http://stackoverflow.com/a/33789603/2476347 servers=[ { :hostname => "uno", :ip => "192.168.100.10", :box => "lamudi/centos-7.0", :ram => 1024, :cpu => 2 }, { :hostname => "duo", :ip => "192.168.100.11", :box => "lamudi/centos-7.0", :ram => 1024, :cpu => 2 } ] 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.network "public_network", type: "dhcp", bridge: "en0: Wi-Fi (AirPort)" node.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--memory", machine[:ram]] end end end end
The code as usual has a lot of potential for upgrade 🙂 if you would have any suggestions please leave comments!