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?
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