ovirt.image-template

oVirt镜像模板

此角色已迁移至 oVirt Ansible Collection,请从那里使用最新版本。此仓库现在为只读,不再用于主动开发。

ovirt.image-template 角色可从外部镜像创建模板。目前,磁盘可以是 Glance 外部提供者中的镜像或 QCOW2 镜像。

注意

请注意,从 Ansible Galaxy 安装此角色时,请运行以下命令:

$ ansible-galaxy install ovirt.image-template

这将把角色下载到与您在命令行上指定的相同名称的目录中,在本例中为 ovirt.image-template。请注意,它区分大小写,因此如果您指定 OVIRT.image-template,它将下载相同的角色,但会将其添加到名为 OVIRT.image-template 的目录中,之后您必须始终使用大写前缀。因此,请小心在命令行上指定角色的名称。

对于 RPM 安装,我们安装了三个旧名称 oVirt.image-templateovirt.image-templateovirt-image-template。 因此,您可以使用这些名称中的任何一个。本文件和本仓库中的示例使用名称 ovirt.image-templateoVirt.image-templateovirt-image-template 角色名称已被淘汰。

要求

  • Ansible 版本 2.9 或更高版本。
  • Python SDK 版本 4.3 或更高版本。
  • oVirt 必须为 4.1 或更高版本,并且必须安装并运行 ovirt-imageio
  • oVirt 引擎的 CA 证书。CA 证书的路径必须在 ovirt_ca 变量中指定。
  • 文件

限制

  • 我们不支持 Ansible 检查模式(干运行),因为此角色使用了少数几个不支持它的模块(命令模块)。 一旦此角色使用的所有模块都支持它,我们将支持该功能。

角色变量

名称 默认值
qcow_url UNDEF(在不使用 glance 的情况下为必填项) QCOW2 镜像的 URL。您可以使用前缀 'file://' 指定本地文件。
qcow_url_client_cert UNDEF 如果需要从已认证站点检索 QCOW,则为客户端证书的路径。
qcow_url_client_key UNDEF 如果需要从已认证站点检索 QCOW,则为客户端密钥的路径。
image_path /tmp/ QCOW2 镜像将下载到的路径。如果是目录,则将使用远程服务器上 URL 的基本名称。
image_checksum UNDEF 如果定义了校验和,下载到的目的文件会计算摘要,以确保其完整性并验证传输是否成功完成。格式::,例如 checksum="sha256:D98291AC[...]B6DC7B97"。
image_cache_download true 设置为 false 时将在执行开始和结束时删除 image_path
template_cluster 默认 创建模板的集群名称。
template_io_threads UNDEF 模板使用的 IO 线程数。0 表示禁用 IO 线程。(在 ansible 2.7 中添加)
template_name mytemplate 模板的名称。
template_memory 2GiB 分配给模板的内存量。
template_memory_guaranteed UNDEF 虚拟机的最小保证内存量
template_memory_max UNDEF 执行内存热插拔的虚拟机内存上限。
template_cpu 1 分配给模板的 CPU 数量。
template_disk_storage UNDEF 磁盘必须创建的数据存储域名称。如果未指定,则自动选择数据存储域。
template_disks [] 指定附加模板磁盘的字典列表。详细描述请见下文。
template_disk_size 10GiB 模板磁盘的大小。
template_disk_name UNDEF 模板磁盘的名称。
template_disk_format UNDEF 模板磁盘的格式。
template_disk_interface virtio 模板磁盘的接口。(选项:virtio,ide,virtio_scsi)
template_seal true “密封”会从文件系统中删除所有特定于机器的配置。在 Windows 上不支持。对 Windows 设置为 'false'。
template_timeout 600 等待模板创建/导入的时间。
template_type UNDEF 模板的类型:桌面、服务器或高性能(仅适用于基于 qcow2 的模板)
template_nics {name: nic1, profile_name: ovirtmgmt, interface: virtio} 指定模板 NIC 的字典列表。
template_operating_system UNDEF 模板的操作系统,例如:其他,rhel_7x64,debian_7,详见 ovirt_template 模块中的其他内容。
glance_image_provider UNDEF(在不使用 qcow_url 的情况下为必填项) Glance 镜像提供者的名称。
glance_image UNDEF(在不使用 qcow_url 的情况下为必填项) 此参数指定要导入的 Glance 提供者中的磁盘名称。
template_prerequisites_tasks UNDEF 仅适用于 qcow 镜像。指定 Ansible 任务文件的路径,在创建模板之前应在虚拟机上执行。请注意,qcow 镜像必须包含报告 IP 地址的客户机代理。

template_disks 字典列表可以包含以下属性:

名称 默认值
name UNDEF (必填) 附加磁盘的名称。
size UNDEF (必填) 附加磁盘的大小。
storage_domain UNDEF 磁盘应创建的存储域名称。如果未传入值,则由 template_disk_storage 设置值。
interface UNDEF 磁盘的接口。如果未传入值,则由 template_disk_interface 设置值。
format UNDEF 指定磁盘的格式。如果未传入值,则由 template_disk_format 设置值。
  • cow - 如果设置,则磁盘将作为稀疏磁盘创建,因此空间将根据需要为卷分配。这种格式也称为薄配置磁盘。
  • raw - 如果设置,磁盘空间将立即分配。这种格式也称为预分配磁盘。
bootable UNDEF 如果磁盘应可启动,则为真。

依赖

无。

示例剧本

---
- name:  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: 从存储在 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:  qcow2.xz 创建模板
  hosts: localhost
  connection: local
  gather_facts: false
  pre_tasks:
    - name: 下载 qcow2.xz 文件
      get_url:
        url: "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2.xz"
        dest: /tmp
      register: downloaded_file

    - name: 提取下载的 QCOW 镜像
      command: "unxz --keep --force {{ downloaded_file.dest }}"

    - name: 设置 qcow_url 为提取的文件
      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

asciicast

许可证

Apache License 2.0

关于项目

Role to create template from external image.

安装
ansible-galaxy install ovirt.image-template
许可证
apache-2.0
下载
42.2k
拥有者
Open Virtual Datacenter