Posts Tagged Under: VirtualBox


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

So far we have come across:

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

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

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

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

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.codingbee.dyndns.org"
  puppetmaster_config.vm.provider "virtualbox" do |v, override|
    v.name = "puppetmaster-def"                                     # this names it for oracle gui 
  end
end



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
end


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