How To Launch Multiple VM’s With Single Vagrantfile
- Last Updated On: December 14, 2017
- By: Scriptcrunch Editorial
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
Scriptcrunch Editorial
Other Interesting Blogs
[50% OFF] Kubernetes Certification Coupons (CKA, CKAD, CKS, KCNA and KCSA)
Looking for CKA coupon and other Kubernetes certification coupon codes? You have come to the right place. Following are the list of
[80% OFF] Linux Foundation Coupon for December 2024
Looking for CKA Coupon and other Linux Foundation certifications coupons? We got you covered. With the latest Linux Foundation Coupon, you can
[65% 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