An ansible role to create QEMU disk images.
This role use the qemu-img
commmand.
This role will install qemu_img
package for your GNU/Linux distribution.
This roles is test on the following GNU/Linux distributions.
- Archlinux
- AlmaLinux
- Debian
- Centos
- Fedora
- RedHat
- Rocky
- Suse
- Ubuntu
-
install
All installation-related tasks are defined in the
install
playbook. This allows you to install the required packages and start/enable the required service withtasks_from
in theinclude_role
,import_role
, … ansible modules.See example below.
-
install
Install the required packages.
- qemu_img: "name space"
The data can be in variables or a list (array). When a list is used, the role will loop over the list and create all defined QEMU disk images.
- dest: required. The destination image.
- src: optional. The source image, a new image will be created if not defined.
- size: optional. required if no src is defined. The size of the destination image.
- owner: uid, default 0. The file owner of the destination image.
- group: gid, default 0. The file group of the destination image.
- mode: mode, default '0400'. The permissions of the destination image.
- remote_src: boolean, default: false. When the source file is in remote host.
- format: format, default: qcow2. The disk image format.
- overwrite: boolean, default: false. Overwrite destination if already exists.
None
---
- name: Install libvirt & co
gather_facts: true
hosts: all
become: true
tasks:
- name: Install the requirements
include_role:
name: "{{ item }}"
tasks_from:
install
with_items:
- stafwag.libvirt
- stafwag.qemu_img
---
- name: Create a new disk image
gather_facts: no
become: true
hosts: localhost
roles:
- role: stafwag.qemu_img
vars:
qemu_img:
dest: datadisk.qcow2
size: 20G
format: qcow2
---
- name: Copy a disk image and resize it
gather_facts: no
become: true
hosts: localhost
roles:
- role: stafwag.qemu_img
vars:
qemu_img:
dest: /var/lib/libvirt/images/tstdebian.qcow2
format: qcow2
size: 50G
src: /home/staf/Downloads/isos/debian/arm64/cloud/debian-10-openstack-arm64.qcow2
---
- name: Create multiple disk images
gather_facts: no
become: true
hosts: localhost
roles:
- role: stafwag.qemu_img
vars:
qemu_img:
- dest: /var/lib/libvirt/images/tstdebian.qcow2
src: /home/staf/Downloads/isos/debian/arm64/cloud/debian-10-openstack-arm64.qcow2
- dest: /var/lib/libvirt/images/tstdebian_data001.qcow
size: 20G
- dest: /var/lib/libvirt/images/tstdebian_data002.qcow
size: 20G
MIT/BSD
Created by Staf Wagemakers, email: [email protected], website: https://www.wagemakers.be, my company: https://mask27.dev