Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi VM in one Vagrantfile. Could I set different memory size for each of them?

Tags:

config.vm.define :web do |web_config|     web_config.vm.box = "saucy"     web_config.vm.host_name = "web"     web_config.vm.network "private_network", ip:"192.168.100.10" end  config.vm.define :db do |db_config|     db_config.vm.box = "saucy"     db_config.vm.host_name = "db"     db_config.vm.network "private_network", ip:"192.168.100.20" end  config.vm.provider :virtualbox do |vb|     vb.customize ["modifyvm", :id, "--memory", "1024"]     vb.customize ["modifyvm", :id, "--cpus", "2"] end 

I have config two VM, 'db' and 'web'. Could I set different memory size for different VM?

like image 329
user984088 Avatar asked Jun 06 '14 01:06

user984088


People also ask

Can I have more than one vagrant box?

Vagrant is able to define and control multiple guest machines per Vagrantfile. This is known as a "multi-machine" environment. These machines are generally able to work together or are somehow associated with each other.

How do you increase memory in vagrant box?

Change memory limit for Vagrant. v. customize ["modifyvm", :id, "--memory", 4096] #<= 4096 equals 4GB total memory. # Set the box name in VirtualBox to match the working directory.

What is Vagrantfile VirtualBox?

Vagrant is an open-source tool that allows you to create, configure, and manage boxes of virtual machines through an easy to use command interface. Essentially, it is a layer of software installed between a virtualization tool (such as VirtualBox, Docker, Hyper-V) and a VM.


1 Answers

2016-08-31: Updated answer to include the whole Vagrantfile per @DarkForce request.

You can do that by moving the vm.provider definition inside each of the vm.define blocks. For example this configuration sets the memory to 2048MB for "web" and 1024MB for "db":

# -*- mode: ruby -*- # vi: set ft=ruby :  Vagrant.configure(2) do |config|   config.vm.box = "ubuntu/trusty64"    config.vm.define :web do |web_config|       web_config.vm.host_name = "web"       web_config.vm.network "private_network", ip:"192.168.100.10"       web_config.vm.provider :virtualbox do |vb|           vb.customize ["modifyvm", :id, "--memory", "2048"]           vb.customize ["modifyvm", :id, "--cpus", "2"]       end   end    config.vm.define :db do |db_config|       db_config.vm.host_name = "db"       db_config.vm.network "private_network", ip:"192.168.100.20"       db_config.vm.provider :virtualbox do |vb|           vb.customize ["modifyvm", :id, "--memory", "1024"]           vb.customize ["modifyvm", :id, "--cpus", "2"]       end   end end 

Note: This example (like many in the Vagrant docs) will only work for VirtualBox. If you wanted your Vagrantfile to also work with VMware or another provider, the customization parameters would be listed separately. For example:

x.vm.provider "vmware_fusion" do |v|   v.vmx["memsize"] = "3000" end x.vm.provider :virtualbox do |v|   v.customize ["modifyvm", :id, "--memory", "3000"] end 
like image 97
BrianC Avatar answered Sep 18 '22 05:09

BrianC