ovirt.image-template
oVirt Image Template
This role has moved to the oVirt Ansible Collection. Please use the latest version there. This repository is now read-only and is not used for active development anymore.
The ovirt.image-template
role creates a template from an external image. It currently supports images from Glance external provider or QCOW2 images.
Note
When you install this role from Ansible Galaxy, run the following command:
$ ansible-galaxy install ovirt.image-template
This command will download the role to a directory with the same name as specified, which is ovirt.image-template
. Be aware that the name is case-sensitive; if you use OVIRT.image-template
, it will create a directory named OVIRT.image-template
instead. So be cautious with the role name when running commands.
For RPM installation, you can use three names: oVirt.image-template
, ovirt.image-template
, and ovirt-image-template
. All documentation and examples in this repository will use ovirt.image-template
. The other two names are now outdated.
Requirements
- Ansible version 2.9 or higher.
- Python SDK version 4.3 or higher.
- oVirt version 4.1 or higher, and ovirt-imageio must be installed and running.
- CA certificate for the oVirt engine. The path to this certificate should be in the
ovirt_ca
variable. - File.
Limitations
- We do not support Ansible Check Mode (Dry Run) for this role because it uses some modules (like the command module) that do not support it. Support may come in the future if all modules used in this role allow it.
Role Variables
Name | Default Value | Description |
---|---|---|
qcow_url | UNDEF (mandatory if glance is not used) | URL of the QCOW2 image. Local files can be prefixed with 'file://'. |
qcow_url_client_cert | UNDEF | Path for client certificate if needed for authenticated retrieval. |
qcow_url_client_key | UNDEF | Path for client key if needed for authenticated retrieval. |
image_path | /tmp | Directory for downloading the QCOW2 image. Uses the URL's base name if it's a directory. |
image_checksum | UNDEF | Checksum for integrity check after download. Format: |
image_cache_download | true | If false, deletes image_path at start and end of execution. |
template_cluster | Default | Name of the cluster where the template will be created. |
template_io_threads | UNDEF | Number of IO threads for the template. 0 disables threading (added in ansible 2.7). |
template_name | mytemplate | Name of the template. |
template_memory | 2GiB | Memory assigned to the template. |
template_memory_guaranteed | UNDEF | Minimum guaranteed memory for the Virtual Machine. |
template_memory_max | UNDEF | Maximum memory limit for hot-plugging memory. |
template_cpu | 1 | Number of CPUs assigned to the template. |
template_disk_storage | UNDEF | Storage domain name for the disk creation. Auto-selected if not specified. |
template_disks | [] | List of disks for the template. See below for details. |
template_disk_size | 10GiB | Size of the template disk. |
template_disk_name | UNDEF | Name of the template disk. |
template_disk_format | UNDEF | Format of the template disk. |
template_disk_interface | virtio | Interface for the template disk (Choices: virtio, ide, virtio_scsi). |
template_seal | true | 'Sealing' removes machine-specific settings from the filesystem. Not supported on Windows (set to false for Windows). |
template_timeout | 600 | Time to wait for the template creation/import. |
template_type | UNDEF | Template type: desktop, server, high_performance (for QCOW2 only). |
template_nics | {name: nic1, profile_name: ovirtmgmt, interface: virtio} | Specifies the NICs for the template. |
template_operating_system | UNDEF | The operating system for the template (examples: other, rhel_7x64, debian_7). |
glance_image_provider | UNDEF (mandatory if qcow_url is not used) | Name of the Glance image provider. |
glance_image | UNDEF (mandatory if qcow_url is not used) | Name of disk to import from Glance provider. |
template_prerequisites_tasks | UNDEF | Path to Ansible tasks to run on the VM before creating the template. Must contain a guest agent to report IP. |
The template_disks
list can contain the following attributes:
Name | Default Value | Description |
---|---|---|
name | UNDEF (Required) | Name of the additional disk. |
size | UNDEF (Required) | Size of the additional disk. |
storage_domain | UNDEF | Storage domain name for disk creation. Defaults to template_disk_storage if not specified. |
interface | UNDEF | Disk interface. Defaults to template_disk_interface if not specified. |
format | UNDEF | Disk format. Defaults to template_disk_format if not specified.
|
bootable | UNDEF | True if the disk should be bootable. |
Dependencies
None.
Example Playbook
---
- name: Create a template from qcow
hosts: localhost
connection: local
gather_facts: false
vars:
engine_fqdn: ovirt-engine.example.com
engine_user: admin@internal
engine_password: 123456
engine_cafile: /etc/pki/ovirt-engine/ca.pem
qcow_url: https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2
#qcow_url: file:///tmp/CentOS-7-x86_64-GenericCloud.qcow2
template_cluster: production
template_name: centos7_template
template_memory: 4GiB
template_cpu: 2
template_disk_size: 10GiB
template_disk_storage: mydata
roles:
- ovirt.image-template
- name: Create a template from a disk stored in glance
hosts: localhost
connection: local
gather_facts: false
vars:
engine_fqdn: ovirt-engine.example.com
engine_user: admin@internal
engine_password: 123456
engine_cafile: /etc/pki/ovirt-engine/ca.pem
glance_image_provider: qe-infra-glance
glance_image: rhel7.4_ovirt4.2_guest_disk
template_cluster: production
template_name: centos7_template
template_memory: 4GiB
template_cpu: 2
template_disk_size: 10GiB
template_disk_storage: mydata
roles:
- ovirt.image-template
- name: Create a template from qcow2.xz
hosts: localhost
connection: local
gather_facts: false
pre_tasks:
- name: Download qcow2.xz file
get_url:
url: "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2.xz"
dest: /tmp
register: downloaded_file
- name: Extract downloaded QCOW image
command: "unxz --keep --force {{ downloaded_file.dest }}"
- name: Set qcow_url to extracted file
set_fact:
qcow_url: "file://{{ (downloaded_file.dest | splitext)[0] }}"
vars:
engine_fqdn: ovirt-engine.example.com
engine_user: admin@internal
engine_password: 123456
engine_cafile: /etc/pki/ovirt-engine/ca.pem
template_cluster: production
template_name: centos7_template
template_memory: 4GiB
template_cpu: 2
template_disk_size: 10GiB
template_disk_storage: mydata
roles:
- ovirt.image-template
License
Apache License 2.0
Role to create template from external image.
ansible-galaxy install ovirt.image-template