Vagrant – Virtual Machine Settings


Previous posts: “Vagrant Provisioning” and “Create a Puppet Server and Agent

In this post we will deal with Vagrant Virtual Machine Settings like CPU, RAM, name, GUI and CPU execution cap. These configuration changes are needed as the default box definitions may not be enough for your testing environment.

Here is our example:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "box1" do |box1|
     box1.vm.box = "ubuntu/trusty64"
     box1.vm.provider "virtualbox" do |vb|
       vb.customize ["modifyvm", :id, "--memory", "2048"]
       vb.customize ["modifyvm", :id, "--cpus", "2"]
       vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
       vb.gui = true
       vb.name = "testmyname"
     end
     box1.vm.network "private_network", ip: "192.168.33.10", adapter: 2
  end
end

Here are the details for each line:

box1.vm.provider “virtualbox” do |vb|
You need to define a new block for each machine to change the settings of it.

vb.customize [“modifyvm”, :id, “–memory”, “2048”]
This line defines RAM as 2 GBs.

vb.customize [“modifyvm”, :id, “–cpus”, “2”]
This line defines two CPUs for the virtual machine.

vb.customize [“modifyvm”, :id, “–cpuexecutioncap”, “50”]
This line ensures that the virtual machine cannot use more than 50% of host CPU.

vb.gui = true
This line enables the GUI of Virtualbox so you can interact with the virtual machine from Virtualbox GUI.

vb.name = “testmyname”
This line gives a meaningful name to your virtual machine in Virtualbox.

Now lets test our config and see what happens with “vagrant up“:

Now I have a Virtualbox GUI for the virtual machine.
Vagrant - Virtual Machine Settings

Checking the details of the Virtualmachine:
As you can see the name, CPU, RAM, CPU execution cap are set correctly.
Vagrant - Virtual Machine Settings 2

Links: https://docs.vagrantup.com/v2/virtualbox/configuration.html

MyFreeCopyright.com Registered & Protected