Home > Infrastructure > VirtualBox Setup for Development

VirtualBox Setup for Development

Goals

  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

Caveats

  • 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.

Components

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

SELINUX=disabled

Turn off Network Manager

1
chkconfig NetworkManager off

Setup the Network Interfaces

Host only interface should be static

1
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:2A:E6:10
TYPE=Ethernet
UUID=597e05d5-f8bc-4a81-bf12-59738e6f44ff
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
NAME="System eth0"
IPADDR=192.168.56.101
NETMASK=255.255.255.0

NAT interface should use DHCP

1
/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
HWADDR=08:00:27:28:09:A8
TYPE=Ethernet
UUID=63925fcf-b675-48b7-8ac6-391756f1c394
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=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:

/usr/share/nginx/html/kickstarts/
 
/usr/share/nginx/html/centos6/

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
#version=DEVEL
 
# 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
install
 
# Use network installation
url --url="http://192.168.56.101/centos6"
 
# Root password
rootpw --plaintext vmr00t
# System authorization information
auth --useshadow --passalgo=sha512
 
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
 
# SELinux configuration
selinux --disabled # This is ignored due to a bug https://bugzilla.redhat.com/show_bug.cgi?id=435300
 
# Do not configure the X Window System
skipx
 
# 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 192.168.56.112 --netmask 255.255.255.0
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
autopart 
#part /boot --fstype="ext4" --size=500
#part / --fstype="ext4" --grow --size=1
#part /home --fstype="ext4" --size=250
#part swap --fstype="swap" --size=256
 
%packages
# Install mandatory, default, and optional packages
@Base --optional
 
%post
mkdir -p /root/.ssh
wget http://192.168.56.101/kickstarts/id_rsa.pub -O /root/.ssh/authorized_keys
yum update -y
 
%end

Setup serving of the CentOS ISO

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

/media/ISOs/CentOS-6.6-x86_64-bin-DVD1.iso

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
roles:
- role: common
 
- hosts: development_hosts
roles:
- role: desktop_environment
- role: software_development
- role: eclipse
 
- hosts: webservers
roles:
- role: webserver

 

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

---
- name: Test connections
ping:
 
- 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
dest=/etc/yum.repos.d/
owner=root group=root mode=0644
 
- name: epel-release install
yum: name=epel-release
enablerepo=ansible-bootstrap-epel
state=present
 
- name: epel repository enable
ini_file: dest=/etc/yum.repos.d/epel.repo
section=epel
option=enabled
value=1
 
- 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=255.255.255.0

Example:

ksdevice=eth0 ks=http://192.168.56.101/kickstarts/base.cfg ip=192.168.56.111 netmask=255.255.255.0

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

[development_hosts]
192.168.56.111
 
[webservers]
192.168.56.112
192.168.56.113

Execute Ansible Playbook

ansible-playbook base.yml -i development

 

Comments are closed.

TOP