RunOpsRun

"Now, here, you see, it takes all the running you can do, to keep in the same place." – The Red Queen

Tag Archives: ubuntu

CFEngine, Jenkins, and Git – Automated Testing and Deployment of your Configuration System – Part 1

Configuration management systems such as CFEngine have greatly reduced the effort required to maintain large numbers of hosts.  Unfortunately they also make it just as easy to propagate mistakes across your entire network.  Using a continuous integration tool such as Jenkins to test and deploy your configuration management system config files as well as the data files it distributes can catch issues before they are given an opportunity to cause outages on your network.

I have not been successful in finding detailed examples of such a setup so I decided document one I’ve been building which supports the following…

  • Testing of the configuration files of the configuration management system
  • Testing of the data files distributed by the system.  Examples: iptables/ipf configs, bind configs and zone files
  • Updates to the configuration system are staged and then deployed into production by Jenkins once tests pass

Creating the Sandbox Environment

For this initial post we’ll be creating a sandbox environment which will host the remaining tools that we setup in later posts.  The sandbox will use the  following software.

Setting up our Workstation

  1. Start downloading an Ubuntu Server 12.04 LTS ISO from http://www.ubuntu.com/download/server
    • I will be using ubuntu-12.04.2-server-amd64.iso
  2. Download and install VirtualBox for your OS from https://www.virtualbox.org/wiki/Downloads
    • My workstation environment is Mac OS X 10.8
  3. Download and install git (optional)

Setting up the Virtual Machines

We’re going to build a network of virtual machines which initially will consist of the following hosts.

  • cfe3srv – Our CFEngine policy server
  • jenkinssrv – Our jenkins instance
  • gitsrv – Host for the our git repository

We could run all of these services on a single host but separating them out is likely to reflect real world environments where services are scattered across boxes.

Creating a host only network

We create a host only interface in VirtualBox which  our various VMs will use to communicate with each other via static IP addresses.  Throughout these posts I’ll use VirtualBox’s command line tool to handle all configuration of the VMs.  You could also use the VirtualBox GUI  instead if that is your preference.

VBoxManage hostonlyif create
VBoxManage hostonlyif ipconfig vboxnet0 --ip 172.16.0.254 --netmask 255.255.0.0

Creating the VMs instances

Next we create the VM instances using the three sets of commands below.  Be sure to set the following two environment variables prior to running the commands.

ISOFILE=~/Downloads/ubuntu-12.04.2-server-amd64.iso
VBOXDIR="VirtualBox VMs"

cfesrv

# Create Virtual Machine for cfe3srv - 1CPU, 256MB RAM
VboxManage createvm --name cfe3srv --ostype Ubuntu_64 --register
VBoxManage modifyvm cfe3srv --memory 512 --nic1 nat --nic2 hostonly --hostonlyadapter2 vboxnet0
# Add CD-ROM and Attach ISO
VBoxManage storagectl cfe3srv --name "IDE Controller" --add ide --controller PIIX4 --hostiocache on --bootable on
VBoxManage storageattach cfe3srv --storagectl "IDE Controller" --type dvddrive --port 0 --device 0 --medium $ISOFILE
# Create Hard Drive - 10G
VBoxManage storagectl cfe3srv --name "SATA Controller" --add sata --controller IntelAHCI --hostiocache on --bootable on
VBoxManage createhd --filename "$VBOXDIR/cfe3srv/cfe3srv.vdi" --size 10240
VBoxManage storageattach cfe3srv --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$VBOXDIR/cfe3srv/cfe3srv.vdi"

jenkinssrv

# Create Virtual Machine for jenkinssrv - 2CPU, 512MB RAM
VboxManage createvm --name jenkinssrv --ostype Ubuntu_64 --register
VBoxManage modifyvm jenkinssrv --memory 512 --cpus 2 --nic1 nat --nic2 hostonly --hostonlyadapter2 vboxnet0
# Add CD-ROM and Attach ISO to it
VBoxManage storagectl jenkinssrv --name "IDE Controller" --add ide --controller PIIX4 --hostiocache on --bootable on
VBoxManage storageattach jenkinssrv --storagectl "IDE Controller" --type dvddrive --port 0 --device 0 --medium $ISOFILE
# Create Hard Drive - 10G
VBoxManage storagectl jenkinssrv --name "SATA Controller" --add sata --controller IntelAHCI --hostiocache on --bootable on
VBoxManage createhd --filename  "$VBOXDIR/jenkinssrv/jenkinssrv.vdi" --size 10240
VBoxManage storageattach jenkinssrv --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$VBOXDIR/jenkinssrv/jenkinssrv.vdi"

gitsrv

# Create Virtual Machine for gitsrv - 1CPU, 256MB RAM
VboxManage createvm --name gitsrv --ostype Ubuntu_64 --register
VBoxManage modifyvm gitsrv --memory 256 --nic1 nat --nic2 hostonly --hostonlyadapter2 vboxnet0
# Add CD-ROM and Attach ISO to it
VBoxManage storagectl gitsrv --name "IDE Controller" --add ide --controller PIIX4 --hostiocache on --bootable on
VBoxManage storageattach gitsrv --storagectl "IDE Controller" --type dvddrive --port 0 --device 0 --medium $ISOFILE
# Create Hard Drive - 10G
VBoxManage storagectl gitsrv --name "SATA Controller" --add sata --controller IntelAHCI --hostiocache on --bootable on
VBoxManage createhd --filename "$VBOXDIR/gitsrv/gitsrv.vdi" --size 10240
VBoxManage storageattach gitsrv --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$VBOXDIR/gitsrv/gitsrv.vdi"

Installing Ubuntu 12.04 LTS

Next we need to power up each of the VMs, install Ubuntu, and setup the static network.  Do the following for each host, replacing cfe3srv with jenkinssrv and gitsrv as needed.

VBoxManage startvm cfe3srv

Since we attached the ISO during VM creation the text based installer should start.  Set the host up as you normally would with the following

  • set eth0 as the main interface, ignore eth1 for now
  • only select ssh server from the software selection list

Once the installation has finished and the host has restarted you will need to login as the user you created during installing and perform the following

Update the /etc/hosts file

Using the editor of your choice (vi or nano are good options)

sudo vi /etc/hosts

Add the following entries to the file

172.16.0.1 cfe3srv
172.16.0.2 jenkinssrv
172.16.0.3 gitsrv

Note: You might want to add these same entries to your workstation’s /etc/hosts file as well as they’ll come in handy later.

Configure eth1

Use an editor such as vi or nano to edit /etc/network/interfaces

sudo vi /etc/network/interfaces

Add the following to the end of the file replacing MYIP with the matching ip address added to /etc/hosts above

auto eth1
iface eth1 inet static
  address MYIP
  netmask 255.255.0.0
  network 172.16.0.0
  broadcast 172.16.255.255

Bring up the new interface

sudo ifup eth1

Rinse and Repeat

Now we need to repeat the installation process above for both jenkinssrv and gitsrv

Testing your setup

At this point you should have a network of three machines which can communicate with each other as well as your workstation.

  1. Restart all three machines
  2. Attempt to ping all three from your workstation.  Example command: ping cfe3srv
  3. Attempt to ssh into all three from your workstation.  Example command: ssh cfe3sv
  4. Attempt to ping each vm from the other two
  5. Attempt to ssh into each vm from the other two

If everything test out we’re ready to move on to Part 2, which should be out over the next few days, where we’ll setup the various software components and wire them together.

Misc notes

I prefer using ssh to access VirtualBox VMs due to the poor performance of the GUI console. Since I don’t need the GUI console I git rid of it by running the VM in headless mode. To start cfe3srv in headless mode you can use either of the following commands.

VBoxManage startvm cfe3srv --type headless # No logging to console
VBoxHeadless --startvm cfe3srv # Logging to console

To see which VMs are running

VBoxManage list runningvms
Follow

Get every new post delivered to your Inbox.