csmart.virt_infra

Ansible Role: Virtual Infrastructure

This Ansible role helps you manage networks and virtual machines (VMs) on KVM hosts. You can handle one or multiple hosts, either individually or as a group.

It's mainly designed for development, where your local machine is the KVM host, and you have sudo access. However, it can be used on remote hosts as well.

You can control the state of your guests—whether they're running, shut down, destroyed, or undefined (which means to delete and clean up).

You can allocate any amount of memory, CPU, storage, and network cards to your VMs, either by groups or individually. It supports various disk types like SCSI, SATA, VirtIO, and NVMe (if supported by the OS).

You can create private NAT networks on the KVM host and add VMs to them. Guests can use these networks, or you can connect them to existing Linux bridge devices or Open vSwitch bridges. You can also configure the network card and MAC addresses for each interface.

This role also supports routed networks and allows you to setup new bridges that connect to existing interfaces on the host.

The role is tested with several Linux distributions using their cloud images, including CentOS, Debian, Fedora, openSUSE, RHEL, and Ubuntu.

To use this role with Red Hat Enterprise Linux (RHEL), set the virt_infra_sm_creds variable for temporary registration during disk preparation. The base images for the guests must already be available in the libvirt images directory.

Guest images are created from the base images. You can keep disk images even after a VM is removed, and the necessary cloud-init ISOs will be created automatically for VM configuration during boot.

The timezone for the guests will match that of the KVM host by default. The role will also add user information and SSH settings to enable direct access.

With this role, you can create and manage different clusters and environments, like OpenStack or Ceph, efficiently.

Requirements

  • A Linux host capable of running KVM is essential.
  • You need some guest images and a basic inventory to start.
  • The user running Ansible must have the ability to communicate with libvirtd via sudo, along with hardware support for KVM and nested virtualization.

Ansible and Jinja version 2.8 or higher might be necessary for specific features included in the role.

Ensure you have at least one SSH key pair on your KVM host. The Ansible playbook can generate an SSH key if none is found.

Install the necessary user-space tools such as qemu-img, virsh, and virt-customize, either manually or via the role.

Download the guest images and place them in the libvirt images directory.

KVM Host Setup

This role can handle the installation and configuration of your KVM host, including dependencies.

Fedora Example

You would typically start by generating an SSH key and installing necessary packages like libvirt, ansible, and other dependencies.

You can find detailed package installation commands for several Linux distributions in the original document, including important steps for Fedora, CentOS, Debian, Ubuntu, and openSUSE.

Using Routed Networks

You can route traffic into new networks, creating a bridge connected to existing interfaces. You need to provide specifics for the routing configuration, such as the bridge name and IP address.

Configuring Bridges with NetworkManager

The role can connect VMs to existing Linux bridges or Open vSwitch bridges. Detailed steps are provided for converting Ethernet devices into bridges using NetworkManager.

Guest Cloud Images

The role is designed to work with standard cloud images from various Linux distributions. Make sure to have these images available in your libvirt storage directory.

Role Variables

There are many configurable variables in the role, allowing for customization of VM states, specifications, and settings. You can override default values as needed.

Example Inventory

An example inventory file format is provided to guide you on structuring your inventory for virtual hosts and guests.

Multiple host group configurations can also be specified in the inventory to manage different VM environments effectively.

Example Playbook

A simple playbook example shows how to utilize this role to set up your infrastructure.

You should also include commands for downloading necessary cloud images, running the playbook against specific host groups, and performing clean-up tasks as needed.

Cleanup

To delete VMs, you can specify the desired VM state in command-line options to manage them accordingly.

Post-Setup Configuration

After setting up your infrastructure, you may want to run additional playbooks to configure your VMs.

License

This project is licensed under GPLv3.

Author Information

Chris Smart, visit his blog for more details.

Informazioni sul progetto

Define and manage guests and networks on a KVM host with Ansible

Installa
ansible-galaxy install csmart.virt_infra
Licenza
gpl-3.0
Download
1.2k
Proprietario
Just another Linux guy.