Skip to content

Latest commit

 

History

History
147 lines (114 loc) · 7.22 KB

File metadata and controls

147 lines (114 loc) · 7.22 KB

Ansible Role jm1.cloudy.libvirt_images

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.libvirt1. 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

Available on Ansible Galaxy in Collection jm1.cloudy.

Requirements

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.

Variables

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

Dependencies

None.

Example Playbook

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.

License

GNU General Public License v3.0 or later

See LICENSE.md to see the full text.

Author

Jakob Meng @jm1 (github, galaxy, web)

Footnotes

  1. If a list item does not contain key uri then it will be initialized from Ansible variables libvirt_uri. 2 3