If you want to create your own Vagrant Base Box using an Oracle Virtualbox as the vagrant provider, you can and it is fairly straight forward. I have detailed the steps in this post. I am using Windows 7 as my “host” operating system on my laptop and I am going to build a Centos 6 base box for my Vagrant template.
I am also going to use the popular configuration management tool puppet to deploy customisations to my Vagrant boxes. In this case I am going to complete a really simple change and add a user called “jenkins”
Let’s get started:
Ensure you have Virtual Box Installed
Vagrant alone doesn’t provide and virtualisation capabilities, it is simply a very useful tool for provisioning VM guests is a quick and standard manner. We will need to provide some type of hypervisor to run our virtual guests. In this example we are going to use the Oracle Virtual Box 4.3.20. It is free, so go ahead and install.
Ensure you have Vagrant installed
Install Guest Additions
This is an important part of the process if you are planning to use Puppet to provision your build which I am. This provides the shared folders capability for accessing the puppet configuration on the host operating system which we will cover later in this guide.
Once your machine is built then ensure the guest additions are installed. There is a useful guide to this here these are the steps I followed
Ensure the Virtual Machine Additions install CD is mounted.
Select your virtual machine, select show. This will bring up a Virtual machine “console”
Choose Devices and “Insert Guest Additions CD image”
Prepare the Vagrant default file
Now you have a a vagrant box to use as a template we can set about creating our vagrant file.
From the c:\myvagrant folder, type the command
This will initialize the directory and create a default vagrant file.
Set Up Puppet
Tp have pupet finish off your vagrant builds we need to create some puppet configuration. So lets do that.
Create a manifests folder
We are going to create a folder where we can hold our puppet configuration. So to do that we need to create a folder under the c:\myvagrant folder called manifests. Go ahead and do that.
Setup a Puppet Manifest File “default.pp”
In this example we are going to use puppet to add a new user to our vm. This user will be named jenkins and will have a home directory of /home/jenkins. Pretty standard stuff but enough to illustrate how to use puppet on a vagrant deployment.
Under the manifests folder, create a file called default.pp and enter the following puppet directives
name => 'jenkins',
comment => 'Jenkins Service Account',
managehome => true,