joaoandreotti.github.io

View on GitHub

Introduction

Ansible-Lab Github Repo.
In this blog I’ll explain how I build my libvirt/kvm lab. The current setup is based on Qubes OS idea of appvms but in a more flexible way.
The main inspiration for this setup was the Red Hat article on how to Build a lab in 36 seconds with ansible.
The article is using a Fedora Cloud qcow2 image, and I want to have a Workstation version lab.
The goal was to create a base qcow2 image based on Fedora Workstation, to later create clones of this image into isolated test environments.

How

Basic functionality

I created two roles, base_image and custom_image. The first for the base image, which is heavily based on the article, and the latter for specialized images.
The base image differs from the article in instead of getting the cloud image, it’ll make a netinst boot of fedora, with a template kickstart file.
I used Example article on kickstart, and Red hat documentation on using unattended installs as a reference to use a kickstart file with libvirt.
To build the kickstart file it was a mix using the ImageFactory Fedora documentation and Libosinfo database.
Both ImageFactory and Libosinfo(virt-install [options] –unattended) are alternatives to do what I did.
Then, creating the derivative image was rather easy using virt-clone and virt-customize tool.

Advanced settings

To further improve the lab creation and maintenance automation, more auxiliary roles were created.

Custom applications configuration

The custom_configuration is for applications configuration.
It contains

Update image

The update_image and replace_image are for image updates.
Executing the update_image role create a copy of image listed on parameters and update them.
Then, executing replace_image deletes the old version and replace for the newly updated one.
This setup was made to create a fail-safe update.

Example

A basic example is to run the complete_lab.yml playbook. It will create a ready to go lab.