You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ansible VMware vMotion模块报错:跨vCenter迁移VM失败

问题根源

community.vmware.vmware_vmotion模块的destination_container参数要求传入vim.ManagedEntity类型的对象(如集群、主机或资源池的实例),但你直接传入了字符串格式的容器名称,导致类型不匹配报错。跨vCenter场景下,模块无法直接通过字符串名称在目标vCenter中解析出对应的实体对象,必须显式获取对象引用。

解决方案

步骤1:获取目标vCenter的容器对象

使用community.vmware.vmware_find_object模块在目标vCenter中查询你要迁移到的容器(比如集群),获取其对象引用:

- name: 查询目标vCenter的集群对象
  community.vmware.vmware_find_object:
    hostname: "{{ dest_vcenter_host }}"
    username: "{{ dest_vcenter_user }}"
    password: "{{ dest_vcenter_pass }}"
    validate_certs: false
    object_type: ClusterComputeResource  # 可根据实际调整为HostSystem/ResourcePool
    object_name: "{{ dest_cluster_name }}"
  register: dest_container_result

步骤2:执行跨vCenter迁移

将查询到的对象作为destination_container的值传入vmware_vmotion模块:

- name: 跨vCenter迁移VM
  community.vmware.vmware_vmotion:
    # 源vCenter配置
    hostname: "{{ src_vcenter_host }}"
    username: "{{ src_vcenter_user }}"
    password: "{{ src_vcenter_pass }}"
    validate_certs: false
    vm_name: "{{ target_vm_name }}"
    # 目标vCenter配置
    destination_hostname: "{{ dest_vcenter_host }}"
    destination_username: "{{ dest_vcenter_user }}"
    destination_password: "{{ dest_vcenter_pass }}"
    destination_validate_certs: false
    # 使用查询到的容器对象
    destination_container: "{{ dest_container_result.objects[0].value }}"
  when: dest_container_result.objects | length > 0
额外检查项
  • 确认两个vCenter之间已配置增强型vMotion兼容性(EVC),CPU架构匹配
  • 确保源VM满足迁移条件:冷迁移需关机,热迁移需符合vSphere跨vCenter热迁移要求
  • 验证AD用户在目标vCenter拥有虚拟机迁移、资源池/集群访问的完整权限
  • 检查ansible.cfg中指定了正确的Python3解释器:interpreter_python = /usr/bin/python3

内容的提问来源于stack exchange,提问作者bfowler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 05:24:21