Tuesday, February 17, 2015

Configure Vagrant

The Vagrant file created by vagrant init is very basic, it has very good comments, so it is easy to figure out what to do. Typically you want to configure timezone, networks, shared folders and other VM settings. For my case, I also have to install proxies.
The Vagrant file is writing in Ruby. After you change configurations, you can use
vagrant reload
vagrant halt
vagrant up
to make new configurations take effect.


Install Plugins

vagrant plugin install vagrant-proxyconf
vagrant plugin install vagrant-timezone
vagrant plugin list

Configure proxy

if Vagrant.has_plugin?("vagrant-proxyconf")
     config.proxy.http = " https://<user>:<password>@<proxy-host>:<proxy-port>"
     config.proxy.https = " https://<user>:<password>@<proxy-host>:<proxy-port>"
     config.proxy.ftp = " https://<user>:<password>@<proxy-host>:<proxy-port>"
     config.proxy.no_proxy = "localhost,,"


Configure timezone

if Vagrant.has_plugin?("vagrant-timezone")
Inside Ubuntu, you can use date command to check Ubuntu’s time.


Configure shared folders

config.vm.synced_folder "../../devops", "/devops"


Configure networks

There is a very good article describing the various networking options Vagrant supports https://www.safaribooksonline.com/library/view/vagrant-up-and/9781449336103/ch04.html.
In my case, as I use Ubuntu for developing and testing purpose, I choose the private network option:
config.vm.network "private_network", ip: ""

With this option, Ubuntu will have an IP address, and my host Win7 will have an IP address

If use public_network, Vagrant has to obtain an IP address via DHCP, sometimes it can be very slow.

Note,  if you fail to run "vagrant up", with errors:
Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter' (VERR_INTNET_FLT_IF_NOT_FOUND).
Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND).
Follow the instruction in http://stackoverflow.com/questions/33725779/failed-to-open-create-the-internal-network-vagrant-on-windows10:
  • uninstall VirtualBox
  • reinstall VirtualBox with the command: C:\Users\Me\Downloads>VirtualBox-5.0.11-104101-Win.exe -msiparams NETWORKTYPE=NDIS5 
 I experienced this issue in Win 7 and Virtualbox 5.0.10/Virtualbox 5.0.14.

Configure VM settings

Here is how I configure my VM settings:
config.vm.provider "virtualbox" do |vb|  
      vb.gui = true 
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
      vb.customize ["modifyvm", :id, "--natdnsproxy1"        , "on"]      
      vb.customize ["modifyvm", :id, "--memory", 8192]
      vb.customize ['modifyvm', :id, '--nicpromisc1', 'allow-all']
      vb.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
      # Note Enabling the I/O APIC is required for 64-bit guest operating systems, especially Windows Vista;
      # it is also required if you want to use more than one virtual CPU in a virtual machine."
      vb.customize ["modifyvm", :id, "--ioapic"  , "on"]
      vb.customize ["modifyvm", :id, "--cpus"    , 2]
      vb.customize ["modifyvm", :id, "--pae"       , "on"]
      vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
      vb.customize ["modifyvm", :id, "--nictype2", "virtio"]     
      vb.customize ["modifyvm", :id, "--chipset" , "ich9"]       

No comments:

Post a Comment