Posts in Category: vagrant

Vagrant – Single/Multi box environments, i.e. “” verses “config.vm.define”

So far we have come across:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| ="puppetlabs/ubuntu-14.04-32-nocm"

Using “” means that your vagrantfile is limited to be able to only spin up a single box.

However instead of “” we could use the “config.vm.define”

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "puppetmaster" do |puppetmaster| ="puppetlabs/ubuntu-14.04-32-nocm"

this approach lets us label each box with a name that is used internally within the vagrant file, in this case I labelled it “puppetmaster”.

If you do a “vagrant up” for both of the above boxes, then the end result is the same, however with the “config.vm.define” approach it leaves the door open to add other boxes

Vagrant – Naming your VMs

You can assign a name to your VM, both in what’s displayed by the vagrant output, and also on the Oracle Virtualbox gui.

config.vm.define :puppetmaster-abc do |puppetmaster_config|        # this names it for vagrant
  puppetmaster_config.vm.hostname = ""
  puppetmaster_config.vm.provider "virtualbox" do |v, override| = "puppetmaster-def"                                     # this names it for oracle gui 

Vagrant – Configuring your VM

So far we succesfully started up our machine, but we encountered a few problems.

The vagrantfile holds all the configurations of our vm. It holds this data in the form of an object that’s been instantiated from the config.vm class.

This section has number attributes that you can set, this attributes are effectively the vm’s settings.

Resolve the timeout warning

According to the documentation, we can fix this by increasing the config.vm.boot_timeout setting: In my case I inserted the following in the block:

config.vm.boot_timeout = 500

Vagrant – Provisioning your first VM

1. Open up git-bash terminal and create a folder that will contain all your personal vagrant files, in my case I have created a top level folder called “vagrant”:

mkdir c:\vagrant\centos

Note: I also create the centos directory in order to keep all my vagrant vms organised.

2. cd into this directory.

3. By default vagrant is designed to automatically download OS images from vagrantcloud. This website is a repository that host hundreds of OS images. The cool thing about this is that it is free to use! On VagrantCloud, search for an image that you are interested in (make sure you pick one that is compatible with your hypervisor, which in my case is virtualbox). In this example, I have searched for centos and will go with the following:

Vagrant – Enabling a CentOS VM’s gui mode

Most vagrant boxes comes without the gui desktop interface. This tutorial will show you how install and access to that gui interface. Let’s use the standard CentOS 7 vm:

$ vagrant init centos/7

The above command will create a Vagrantfile.

Next open up the vagrant file and ensure the following virtualbox setting section exists:

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

Log into your vm:

$ vagrant ssh

Then switch to root:

$ sudo -i 

Then install the gui desktop collection of packages:

$ yum groupinstall -y 'gnome desktop'
$ yum install -y 'xorg*'

Next uninstall the following packages:

yum remove -y initial-setup initial-setup-gui

These packages are to do with agreeing to EULA agreements, which means it requires user interaction, which can prevent automated startups via vagrant.

Next switch to the gui

Vagrant – Installing Vagrant on Windows

Setting up Vagrant on Windows

You can install virtualbox and vagrant from the powershell command-line with the help of Powershell’s community repository, Chocolatey:

1. Open up a powershell terminal (in admin mode)
2. Run the following to connect to the chocolatey library (you can skip this step if the “choco” command already works):

iex ((new-object net.webclient).DownloadString(''))

3. Now install vagrant, virtualbox, and cyg-get using the following command:

cinst virtualbox vagrant cyg-get

note: cinst is a an alias for “choco install”

Note: cyg-get is something we are installing as part of an intermediary step for installing openssh. We’ll cover more about this later.

4. Also install git-bash.

5. Check that similar folders to these have now been created:

  • – VirtualBox : C:\Program Files\Oracle\VirtualBox
  • – Vagrant : C:\HashiCorp\Vagrant\bin
  • – cyg-get : C:\tools\cygwin and also: C:\tools\cygwin\bin
  • – chocolatey : C:\ProgramData\chocolatey\bin

Notice that vagrant doesn’t get