VirtualBox Setup for Development

Filed in Infrastructure Leave a comment


  1. Kickstart a virtual machine into a base state useful for building various types of machines
  2. Use Ansible to configure and manage the state of those machines


  • I develop exclusively in Linux, primarily CentOS so the following instructions are tailored to that.
  • There are some manual steps like kickstarting,  that I would like to automate at some point in the future.
  • Transferring root’s public key to the new machine with the kickstart is terrible, but will suffice for now.


Setup the Master VM

I need a Master VM to serve the kickstart files, ISO files, and to run Ansible from. For now, this machine will be a snowflake (a unique machine) and I will back up it’s state using Virtual Box. I’ll need two network interfaces, one to communicate with the outside world and the other to communicate with the Host Only network the managed VMs will be on.

  • Base Memory: 4096 MB
  • Storage: 24 GB dynamically allocated
  • Network
    • Adapter 1: Host only
    • Adapter 2: NAT

Install CentOS

  1. Download the ISO from an appropriate mirror.
  2. Use the Virtual Box manager mount the ISO to the optical drive of your VM.
  3. Start the VM
  4. Review these step by step instructions. (Skip the network steps)

CentOS Settings

Once the installation has completed and the machine has rebooted login with the username and password you supplied during install. Complete the following steps. I usually just sudo to root for this. It will require the root password that you set during installation.

[swright@master ~]# sudo su -

Turn off SELinux since we wont really need it for a development system

[root@master ansible_playbooks]# vi /etc/selinux/config


Turn off Network Manager

chkconfig NetworkManager off

Setup the Network Interfaces

Host only interface should be static

NAME="System eth0"

NAT interface should use DHCP


Setup the EPEL Repo

Instructions for setting up EPEL repo.

Install and Setup Nginx

yum install nginx

For now I will just use the default server for Nginx. Create the following directories:


Setup the Kickstart File

I want the kickstart to only create the most basic of machines. I will use Ansible to do any further package installation or configuration.

Content of the Kickstart File

#platform=x86, AMD64, or Intel EM64T
# Firewall configuration
firewall --enabled --service=http,ftp,ssh,telnet,smtp,http,ftp,ssh,telnet,http,ftp,ssh,http,ftp,ssh,ssh
# Install OS instead of upgrade
# Use network installation
url --url=""
# Root password
rootpw --plaintext vmr00t
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled # This is ignored due to a bug
# Do not configure the X Window System
# Installation logging level
logging --level=info
# Reboot after installation
reboot --eject
# System timezone
timezone America/New_York
# Network information
#network --bootproto=static --device=eth0 --onboot=on --ip --netmask
network --bootproto=dhcp --device=eth1 --onboot=on
# System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Disk partitioning information
#part /boot --fstype="ext4" --size=500
#part / --fstype="ext4" --grow --size=1
#part /home --fstype="ext4" --size=250
#part swap --fstype="swap" --size=256
# Install mandatory, default, and optional packages
@Base --optional
mkdir -p /root/.ssh
wget -O /root/.ssh/authorized_keys
yum update -y

Setup serving of the CentOS ISO

Download the latest ISO from a CentOS Mirror. I put it here:


Then you need to mount the ISO to the file system. I do this in a location that Nginx can serve from. Edit fstab and add the following:

/media/ISOs/CentOS-6.6-x86_64-bin-DVD1.iso /usr/share/nginx/html/centos6 iso9660 loop 0 0

Install and Setup Ansible

yum install ansible

Create the Play Book

This is the basic layout I used for my Play Book.

Following are the base playbook that defines with roles are assigned to which host groups. I also included the playbook for the common role. There are more obviously but I wont add them here.

[root@master ~]# cat /root/workspace/ansible_playbooks/base.yml

- hosts: all
- role: common
- hosts: development_hosts
- role: desktop_environment
- role: software_development
- role: eclipse
- hosts: webservers
- role: webserver


[root@master ~]# cat /root/workspace/ansible_playbooks/roles/common/tasks/main.yml

- name: Test connections
- name: Install Python package that will allow Ansible to disable SELinux
yum: name=libselinux-python state=present
- name: Disable SELinux
selinux: state=disabled
- name: bootstrap epel-release install
copy: src=ansible-bootstrap-epel.repo
owner=root group=root mode=0644
- name: epel-release install
yum: name=epel-release
- name: epel repository enable
ini_file: dest=/etc/yum.repos.d/epel.repo
- name: Install latest version of Subversion
yum: name=subversion state=latest
- name: Add the swright user
user: name=swright password=******

The process to create a new machine

Setup the VM

Create a new VM using Virtual Box. Give it the CPU, RAM and storage space you need. Create two network interfaces. The first should be host only, and the second should be a NAT.

Boot and run kickstart

You’ll need a CentOS ISO locally to start the install. I use the netinstall.iso. Insert it into the virtual optical drive. Boot the machine. At the install type screen press the TAB key and a prompt will appear. Enter the following information.

ksdevice=<network interface> ks=<url for kickstart file> ip=<address for this machine> netmask=


ksdevice=eth0 ks= ip= netmask=

The rest of the installation will automatic.

Add the machine to Ansible’s inventory

Add the host IP address to a group in the inventory file. Since I am setting up dev box I will add the IP to the development_hosts group in the development inventory file.

[root@master ansible_playbooks]# cat development


Execute Ansible Playbook

ansible-playbook base.yml -i development