community.vmware.vmware_guest_cross_vc_clone 模块 – 跨 vCenter VM/模板克隆

注意

此模块是 community.vmware 集合(版本 5.2.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.vmware

要在 playbook 中使用它,请指定: community.vmware.vmware_guest_cross_vc_clone

概要

  • 此模块可用于跨 vCenter vm/模板克隆

参数

参数

注释

destination_datastore

字符串 / 必需

目标数据存储或数据存储集群的名称。

如果指定了数据存储集群名称,我们将在该集群中找到 Storage DRS 推荐的数据存储。

destination_host

字符串 / 必需

目标主机的名称。

destination_resource_pool

字符串

目标资源池。

如果未提供,将使用目标主机的父级的资源池。

destination_vcenter

字符串 / 必需

目标 VCenter 的主机名或 IP 地址。

destination_vcenter_password

字符串 / 必需

目标 VCenter 的密码。

destination_vcenter_port

整数

在目标 VCenter 中建立连接的端口。

默认值: 443

destination_vcenter_username

字符串 / 必需

目标 VCenter 的用户名。

destination_vcenter_validate_certs

布尔值

指示是否需要在目标 VCenter 上进行证书验证的参数。

选项

  • false ← (默认值)

  • true

destination_vm_folder

字符串 / 必需

目标文件夹,部署克隆虚拟机的绝对路径。

示例

folder: vm

folder: ha-datacenter/vm

folder: /datacenter1/vm

destination_vm_name

字符串 / 必需

克隆虚拟机的名称。

hostname

字符串

vSphere vCenter 或 ESXi 服务器的主机名或 IP 地址。

如果任务中未指定该值,则将使用环境变量 VMWARE_HOST 的值。

is_template

布尔值

指定是否应将新的虚拟机标记为模板。

选项

  • false ← (默认值)

  • true

moid

字符串

如果已知,则要管理的 vm/模板实例的托管对象 ID,这是仅在单个 vCenter 实例中唯一的标识符。

如果未提供 nameuuid,则此参数为必需。

name

字符串

虚拟机或模板的名称。

如果未提供参数 uuidmoid,则此参数为必需。

password

别名: pass, pwd

字符串

vSphere vCenter 或 ESXi 服务器的密码。

如果任务中未指定该值,则将使用环境变量 VMWARE_PASSWORD 的值。

port

整数

vSphere vCenter 或 ESXi 服务器的端口号。

如果任务中未指定该值,则将使用环境变量 VMWARE_PORT 的值。

默认值: 443

proxy_host

字符串

将接收所有 HTTPS 请求并转发它们的代理的地址。

格式为主机名或 IP。

如果任务中未指定该值,则将使用环境变量 VMWARE_PROXY_HOST 的值。

proxy_port

整数

将接收所有 HTTPS 请求并转发它们的 HTTP 代理的端口。

如果任务中未指定该值,则将使用环境变量 VMWARE_PROXY_PORT 的值。

state

字符串

已部署的虚拟机的状态。

如果设置为 present 且虚拟机不存在,则会创建虚拟机。

如果设置为 present 且虚拟机存在,则不会采取任何操作。

如果设置为 poweredon 且虚拟机不存在,则会创建虚拟机并启动电源。

如果设置为 poweredon 且虚拟机存在,则不会采取任何操作。

选项

  • "present" ← (默认值)

  • "poweredon"

timeout

整数

在 community.vmware 3.5.0 中添加

以秒为单位的超时时间。当达到超时时间时,模块将失败。

默认值: 3600

use_instance_uuid

布尔值

是否使用 VMware 实例 UUID 而不是 BIOS UUID。

选项

  • false ← (默认值)

  • true

username

别名: admin, user

字符串

vSphere vCenter 或 ESXi 服务器的用户名。

如果任务中未指定该值,则将使用环境变量 VMWARE_USER 的值。

uuid

字符串

要从中克隆虚拟机/模板实例的 UUID,这是 VMware 的唯一标识符。

如果未提供参数 namemoid,则此为必填参数。

validate_certs

布尔值

允许在 SSL 证书无效时进行连接。当证书不受信任时,设置为 false

如果任务中未指定该值,则将使用环境变量 VMWARE_VALIDATE_CERTS 的值。

选项

  • false

  • true ← (默认)

备注

注意

  • 所有模块都需要 API 写入权限,因此免费 ESXi 许可证不支持。

  • 所有变量和 VMware 对象名称都区分大小写。

示例

# Clone template
- name: clone a template across VC
  community.vmware.vmware_guest_cross_vc_clone:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    name: "test_vm1"
    destination_vm_name: "cloned_vm_from_template"
    destination_vcenter: '{{ destination_vcenter_hostname }}'
    destination_vcenter_username: '{{ destination_vcenter_username }}'
    destination_vcenter_password: '{{ destination_vcenter_password }}'
    destination_vcenter_port: '{{ destination_vcenter_port }}'
    destination_vcenter_validate_certs: '{{ destination_vcenter_validate_certs }}'
    destination_host: '{{ destination_esxi }}'
    destination_datastore: '{{ destination_datastore }}'
    destination_vm_folder: '{{ destination_vm_folder }}'
    state: present
  register: cross_vc_clone_from_template

- name: clone a VM across VC
  community.vmware.vmware_guest_cross_vc_clone:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: "{{ vcenter_password }}"
    name: "test_vm1"
    destination_vm_name: "cloned_vm_from_vm"
    destination_vcenter: '{{ destination_vcenter_hostname }}'
    destination_vcenter_username: '{{ destination_vcenter_username }}'
    destination_vcenter_password: '{{ destination_vcenter_password }}'
    destination_host: '{{ destination_esxi }}'
    destination_datastore: '{{ destination_datastore }}'
    destination_vm_folder: '{{ destination_vm_folder }}'
    state: poweredon
  register: cross_vc_clone_from_vm

- name: check_mode support
  community.vmware.vmware_guest_cross_vc_clone:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: "{{ vcenter_password }}"
    name: "test_vm1"
    destination_vm_name: "cloned_vm_from_vm"
    destination_vcenter: '{{ destination_vcenter_hostname }}'
    destination_vcenter_username: '{{ destination_vcenter_username }}'
    destination_vcenter_password: '{{ destination_vcenter_password }}'
    destination_host: '{{ destination_esxi }}'
    destination_datastore: '{{ destination_datastore }}'
    destination_vm_folder: '{{ destination_vm_folder }}'
  check_mode: true

返回值

通用返回值在此处 记录,以下是此模块独有的字段

描述

vm_info

字典

关于虚拟机的元数据

返回: 总是

示例: {"datastore": "", "host": "", "power_on": "", "vcenter": "", "vm_folder": "", "vm_name": ""}

作者

  • Anusha Hegde (@anusha94)