This role helps with managing cloud images in libvirt storage pools from Ansible variables. For example, it
allows to download and add cloud images of CentOS, Debian, Fedora and Ubuntu as libvirt (block storage) volumes to storage pools
with variable libvirt_images
. This variable is defined as a list where each list item is a dictionary of parameters
that will be passed to module jm1.libvirt.volume_import
from collection jm1.libvirt
1.
For example, to fetch the latest cloud image of Debian 11 (Bullseye) and add it to the libvirt storage pool default
of
the local libvirt daemon (run by current Ansible user on the Ansible controller), define variable libvirt_images
in
group_vars
or host_vars
as such:
# connect from Ansible controller to local libvirt daemon
ansible_connection: local
libvirt_images:
- # no checksum because image is updated every week
format: 'qcow2'
image: https://cdimage.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2
name: debian-11-genericcloud-amd64.qcow2
pool: 'default'
state: present
# libvirt connection uri
# Ref.: https://libvirt.org/uri.html
libvirt_uri: 'qemu:///session'
Use role jm1.cloudy.libvirt_pools
to create the libvirt storage pool default
as shown by
the example playbook of this role.
Once the previous role has finished, execute this role jm1.cloudy.libvirt_images
. It will pass each item of the
libvirt_images
list one after another as parameters to module jm1.libvirt.volume_import
from collection jm1.libvirt
1. If a libvirt volume with the same
name
already exists, it will not be changed.
Tested OS images
- Cloud image (
amd64
) of Debian 10 (Buster) - Cloud image (
amd64
) of Debian 11 (Bullseye) - Cloud image (
amd64
) of Debian 12 (Bookworm) - Cloud image (
amd64
) of Debian 13 (Trixie) - Cloud image (
amd64
) of CentOS 7 (Core) - Cloud image (
amd64
) of CentOS 8 (Stream) - Cloud image (
amd64
) of CentOS 9 (Stream) - Cloud image (
amd64
) of Fedora Cloud Base 40 - Cloud image (
amd64
) of Ubuntu 18.04 LTS (Bionic Beaver) - Cloud image (
amd64
) of Ubuntu 20.04 LTS (Focal Fossa) - Cloud image (
amd64
) of Ubuntu 22.04 LTS (Jammy Jellyfish) - Cloud image (
amd64
) of Ubuntu 24.04 LTS (Noble Numbat)
Available on Ansible Galaxy in Collection jm1.cloudy.
This role uses module(s) from collections community.libvirt
and jm1.libvirt
. To install these collections you may follow the steps described in README.md
using the provided requirements.yml
.
Name | Default value | Required | Description |
---|---|---|---|
libvirt_images |
[] |
false | List of parameter dictionaries for module jm1.libvirt.volume_import from collection jm1.libvirt 1 |
libvirt_uri |
qemu:///system |
false | libvirt connection uri |
None.
First, use role jm1.cloudy.libvirt_pools
to create a libvirt storage pool with name
default
as shown in the introduction of that role.
- hosts: all
vars:
# Variables are listed here for convenience and illustration.
# In a production setup, variables would be defined e.g. in
# group_vars and/or host_vars of an Ansible inventory.
# Ref.:
# https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html
# https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
# connect from Ansible controller to local libvirt daemon
ansible_connection: local
libvirt_images:
- # no checksum because image is updated every week
format: 'qcow2'
image: https://cdimage.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2
name: debian-11-genericcloud-amd64.qcow2
pool: 'default'
state: present
# libvirt connection uri
# Ref.: https://libvirt.org/uri.html
libvirt_uri: 'qemu:///session'
roles:
- name: Setup OS images as libvirt block storage volumes
role: jm1.cloudy.libvirt_images
tags: ["jm1.cloudy.libvirt_images"]
For a complete example on how to use this role to add cloud images of CentOS, Debian and Ubuntu, refer to hosts lvrt-lcl-session
and lvrt-lcl-system
as well
as variable libvirt_images
like defined in host_vars
and group_vars/svc_libvirt.yml
from the provided examples
inventory. The top-level README.md
describes how these hosts can be
provisioned with playbook playbooks/site.yml
.
For instructions on how to run Ansible playbooks have look at Ansible's Getting Started Guide.
GNU General Public License v3.0 or later
See LICENSE.md to see the full text.
Jakob Meng @jm1 (github, galaxy, web)