Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase memory of a particular vagrant box

I have this Vagrantfile. Here I defined the memory to be 2048 for all VMs. But I want my puppet master to have 4096 and agents to have 2048. How to do that?

Vagrant.configure("2") do |config|
  config.vm.synced_folder ".", "/vagrant", type: "virtualbox"

  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
  end

  config.vm.define "puppetmaster" do |pm|
    pm.vm.box = "centos/7"
    pm.vm.network "private_network", ip: "192.168.33.10"
    pm.vm.hostname = "puppetmaster"
  end

  config.vm.define "puppet-agent-centos" do |pac|
    pac.vm.box = "centos/7"
    pac.vm.network "private_network", ip: "192.168.33.11"
    pac.vm.hostname = "centos-agent"
  end

  config.vm.define "puppet-agent-ubuntu" do |pau|
    pau.vm.box = "ubuntu/xenial64"
    pau.vm.network "private_network", ip: "192.168.33.12"
    pau.vm.hostname = "ubuntu-agent"
  end
end

Thanks!

like image 491
awwwd Avatar asked May 16 '17 10:05

awwwd


People also ask

How do you increase memory in vagrant box?

Increase Memory and CPU on Vagrant machine from commandlineDefine the RAM size and CPU count like below. As per the above configuration, I have defined 2 GB RAM and 2 CPU core to my Vagrant machine. Make sure you have added these lines before the last "end" line. Press ESC key, and type :wq to save the file and exit.

What does vagrant provision do?

Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process. This is useful since boxes typically are not built perfectly for your use case.


1 Answers

You can easily do that by overriding the value for a specific VM

  config.vm.define "puppetmaster" do |pm|
    pm.vm.box = "centos/7"
    pm.vm.network "private_network", ip: "192.168.33.10"
    pm.vm.hostname = "puppetmaster"

    pm.vm.provider "virtualbox" do |pmv|
      pmv.memory = 4096
    end
  end

so your whole file becomes

Vagrant.configure("2") do |config|
  config.vm.synced_folder ".", "/vagrant", type: "virtualbox"

  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
  end

  config.vm.define "puppetmaster" do |pm|
    pm.vm.box = "centos/7"
    pm.vm.network "private_network", ip: "192.168.33.10"
    pm.vm.hostname = "puppetmaster"

    pm.vm.provider "virtualbox" do |pmv|
      pmv.memory = 4096
    end
  end

  config.vm.define "puppet-agent-centos" do |pac|
    pac.vm.box = "centos/7"
    pac.vm.network "private_network", ip: "192.168.33.11"
    pac.vm.hostname = "centos-agent"
  end

  config.vm.define "puppet-agent-ubuntu" do |pau|
    pau.vm.box = "ubuntu/xenial64"
    pau.vm.network "private_network", ip: "192.168.33.12"
    pau.vm.hostname = "ubuntu-agent"
  end
end
like image 81
Frederic Henri Avatar answered Nov 14 '22 22:11

Frederic Henri