我尝试使用 ansible 测试一个简单的剧本。我的目标是用它创建一个新的虚拟机。
---
# create a new VM from a template
- name: VM from template
hosts: localhost
gather_facts: false
connection: local
vars:
vcenter_hostname: vcenter-app
vcenter_user: john@doe
vcenter_pass: blabla6
esxhost: esx-4.cbalo.fr
datastore: VM-PROD-02-NORMAL
vmtemplate: Centos7-template
name: "newvm2"
notes: Ansible Test
dumpfacts: False
tasks:
- name: Create VM from template
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
esxi_hostname: "{{ esxhost }}"
datacenter: CD06
folder: Test
name: "{{ name }}"
template: "{{ vmtemplate }}"
disk:
- size_gb: "{{ disk_size | default(17) }}"
type: thin
datastore: "{{ datastore }}"
hardware:
memory_mb: "{{ vm_memory | default(1024) }}"
wait_for_ip_address: True
state: present
register: newvm2
与我的 VMcenter 的连接正常,但我看到了错误消息:
**ansible-playbook test_vmware.yml**
PLAY [Create VM from template] ******************************************************************************************************************************************************
TASK [Clone VM from template] *******************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to create a virtual machine : Cannot complete the operation because the file or folder /vmfs/volumes/5d25e76b-5475ac54-9cdb-e4434b69d662/newvm2/newvm2.vmdk already exists"}
即使我改了名字新虚拟机2对于另一个,我仍然收到相同的消息。有人能帮我解决这个情况吗?
非常感谢
答案1
你可能会看到https://github.com/ansible/ansible/issues/55551
此修复包含在 Ansible 2.8.3 或更高版本中。
还有一个提示:当你遇到 Ansible 问题时,最好包含“ ansible --version ”的输出