
How To Launch Multiple VM’s With Single Vagrantfile
- Last Updated on: December 14, 2017
- By: scriptcrunch
Often times you might want to launch more than one VM of a related application with different configurations. In this case, you don’t have to create multiple vagrant configurations. You can use a single Vagrantfile with multiple configurations as shown below. The best part is you can start VM’s individually rather than starting all VM’s at once.
An example configuration which launches three VM’s is shown below.
Vagrant.configure("2") do |config| config.vm.provision "shell", inline: "sudo yum update -y" config.vm.define "master" do |master| master.vm.box = "bento/centos-7.1" master.vm.network "private_network", ip: "192.168.5.2" master.vm.hostname = "master" master.vm.provider "virtualbox" do |vb| vb.memory = "2048" vb.cpus = "2" end end config.vm.define "node1" do |node1| node1.vm.box = "bento/centos-7.1" node1.vm.network "private_network", ip: "192.168.5.3" node1.vm.hostname = "node1" node1.vm.provider "virtualbox" do |vb| vb.memory = "2048" vb.cpus = "2" end end config.vm.define "node2" do |node2| node2.vm.box = "bento/centos-7.1" node2.vm.network "private_network", ip: "192.168.5.4" node2.vm.hostname = "node2" node2.vm.provider "virtualbox" do |vb| vb.memory = "2048" vb.cpus = "2" end end end
To start the VM’s, open the terminal and browse to the location which contains the Vagrantfile. execute the following command to bring up the VM’s.
vagrant up
To ssh, you can use the individual VM names mentioned in the configuration.
For example,
vagrant ssh master
Other Interesting Blogs

CKA Exam Study Guide: Certified Kubernetes Administrator
Passing the cloud-native Certified Kubernetes Administrator (CKA) exam is not a cakewalk. To pass the CKA exam, you should have enough hands-on

Linux Foundation Coupon for 2023
Hi Techies, I wanted to let you know about a pretty sweet deal with the Linux Foundation Coupon that is running now.

[35% OFF] Linux Foundation LFCA, LFCS & LFCT Exam Voucher Codes
Linux Foundation has announced up to a $284 discount on its Linux certification programs Linux Foundation Certified IT Associate (LFCA) and Linux