Vagrant

Index

Introduction

Vagrant is an amazing tool for managing virtual machines via a simple to use command line interface. With a simple vagrant up you can be working in a clean environment based on a standard template.

Proxy configuration

Reference > http://tmatilai.github.io/vagrant-proxyconf/

Install vagrant plugin 'vagrant-proxyconf'

Note: Behind a proxy, tell vagrant which proxy to use for downloading the plugin (environment variables)

HTTPS_PROXY=http://172.23.220.43:3128/

HTTP_PROXY=http://172.23.220.43:3128/

NO_PROXY=192.*.*.*,home.com,*.aventail.com,.seanet.com

>vagrant plugin install vagrant-proxyconf
Installing the 'vagrant-proxyconf' plugin. This can take a few minutes...
Installed the plugin 'vagrant-proxyconf (1.5.2)'!

This plugin works with a three configuration level that can be overriden, in this example we're using the host OS environment variables which are picked up by vagrant and passed to the guest OS.

In this example, the host has IP address 172.23.220.43 and cntlm installed with specific cntlm.ini configuration to expose it:

Listen 3128

Listen 172.23.220.43:3128

The host environment variables have, therefore, configured this way:

>set VAGRANT
VAGRANT_FTP_PROXY=http://172.23.220.43:3128
VAGRANT_HTTPS_PROXY=http://172.23.220.43:3128
VAGRANT_HTTP_PROXY=http://172.23.220.43:3128
VAGRANT_NO_PROXY=localhost,10.*.*.*,127.*.*.*,.ibermatica.com,.intranet.ibermatica

Boxes available

Hashicorp

https://atlas.hashicorp.com/boxes/search

Vagrantbox.es

http://www.vagrantbox.es/

To use the available boxes just replace {title} and {url} with the information in the table below.

$ vagrant box add {title} {url} $ vagrant init {title} $ vagrant up

VirtualBox Memory and CPU config

On Vagrant file, if needed, uncomment or add to, eg, increase the default 512MB to 3.5GB (ensure host machine has more physical RAM !):

 config.vm.provider "virtualbox" do |vb|
     vb.memory = 3584
     vb.cpus = 2
 end

Port forwarding config

If needed, on Vagrant file uncomment or add eg:

  config.vm.network "forwarded_port", guest: 22, host: 22, host_ip: "127.0.0.2"
  config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.2"
  config.vm.network "forwarded_port", guest: 9990, host: 9990, host_ip: "127.0.0.2"

Stop a VM managed by Vagrant

Reference > https://www.vagrantup.com/docs/cli/halt.html

vagrant halt

Samples

Ubuntu Server 14.04 (Vagrantbox.es)

Vagrantbox.es uses the 'current' version which, at time of writing, is newer than the one used by Hashicorp; even thought both of them point to the official Ubuntu build for the Cloud [https://cloud-images.ubuntu.com/vagrant/trusty/]

$ vagrant box add "Official Ubuntu 14.04 daily Cloud Image amd64 (Development release, No Guest Additions)" https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box $ vagrant init "Official Ubuntu 14.04 daily Cloud Image amd64 (Development release, No Guest Additions)" $ vagrant up

Ubuntu Server 14.04 LTS (Hashicorp)

$ vagrant init ubuntu/trusty64
$ vagrant up --provider virtualbox