So a few weeks back I started messing around with Perl a bit.  I’ve been creating a few new CentOS VM’s lately on my home network, so I figured a host customization script would be useful.  My deployment system just consists of a basic CentOS 6 VM that I use as a template.

There are probably better ways of doing a lot of this, but it was a fun project to learn a bit about Perl’s regex capabilities.

This script sets the hostname, static IP addresses, and regenerates SSH host keys.  It also renames the LVM volume group to include the hostname (like myhostname_vg0).  This took a few unbootable VM’s to get right…VMware snapshots to the rescue!  :) Beyond just renaming the VG, it also updates fstab, grub.conf and runs mkinitrd.

It accounts for the fact that the MAC address will change, and makes sure that the new NIC will be seen as eth0.

No guarantees all of this will work for you…it relies on lots of ugly regex and may fail badly on a system that doesn’t have the same configuration files as my template VM does.