search

Thursday, February 18, 2016

Conditions in the Vagrantfile

Every developer could have different hardware configuration. Let's say one is ready to provision a virtual machine with 4 cpus and another - only with 2 cpus. It would be nice to handle this situation with environmental variables:
Vagrant.configure(2) do |config|
  config.vm.box = "box-cutter/debian81"

  config.vm.network "private_network", ip: "192.168.33.10"
  config.ssh.forward_agent = true

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "4096"
    if ENV.has_key?('VAGRANT_CPUS')
      vb.cpus = ENV['VAGRANT_CPUS']
    else
      vb.cpus = "2"
    end
  end
end
With that config the number of the provisioned cpus can be controled via VAGRANT_CPUS environmental variable.

No comments:

Post a Comment