stafwag.qemu_img

Ansible Role: qemu_img

This is an Ansible role designed to create QEMU disk images.

Requirements

This role uses the qemu-img command. It will install the qemu_img package for your GNU/Linux system. The role has been tested on the following GNU/Linux distributions:

  • Archlinux
  • AlmaLinux
  • Debian
  • CentOS
  • Fedora
  • RedHat
  • Rocky
  • Suse
  • Ubuntu

Role Tasks, Tags, Variables, and Templates

Tasks

  • install

    All tasks related to installation are listed in the install playbook. This helps install the needed packages and start/enable any required services using tasks_from in the include_role, import_role, and other Ansible modules.

    See the example below.

Tags

  • install

    This is used to install the necessary packages.

Variables

  • qemu_img: "name space"

Data can be provided as variables or a list (array). When using a list, the role will loop through it and create all specified QEMU disk images.

  • dest: required. The location for the new image.
  • src: optional. The source image; a new image will be created if not provided.
  • size: optional. Required if no source image is given. Defines the size of the new image.
  • owner: user ID, default is 0. The owner of the new image file.
  • group: group ID, default is 0. The group of the new image file.
  • mode: permissions, default is '0400'. The access permissions for the new image.
  • remote_src: boolean, default is false. Whether the source file is on a remote host.
  • format: format type, default is qcow2. The format of the disk image.
  • overwrite: boolean, default is false. Whether to overwrite the destination if it already exists.

Dependencies

None

Example Playbooks

Install Required Packages

---
- name: Install libvirt & related packages
  gather_facts: true 
  hosts: all
  become: true
  tasks:
    - name: Install the necessary packages
      include_role:
        name: "{{ item }}"
        tasks_from:
          install
      with_items:
        - stafwag.libvirt 
        - stafwag.qemu_img

Create a New QEMU Image

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

Copy and Resize a Disk Image

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

Create Multiple Disk Images

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

License

MIT/BSD

Author Information

Created by Staf Wagemakers, email: staf@wagemakers.be, website: https://www.wagemakers.be, company: https://mask27.dev

Informazioni sul progetto

An ansible role to create qemu_img images

Installa
ansible-galaxy install stafwag.qemu_img
Licenza
mit
Download
473
Proprietario