This script shows how you might have a library of premade virtual machines ready for cloning, but as a final step you use libguestfs or guestfish to customize some configuration files inside the VM before it's ready to go.

In this simple recipe, we overwrite the /etc/resolv.conf file with a new nameserver entry, and change /etc/HOSTNAME.

There are lots of possible improvements to this script, such as using qcow2 snapshots so that cloned VMs share storage with their "parent" preimages.

For more information about cloning images using libvirt and libguestfs see Richard Jones's procedure for cloning a Fedora VM.