我正在尝试使用ansible playbook在独立的ESXi主机上创建VM。 我在下面的链接中看到我们可以使用" ha-datacenter"作为数据中心名称,使ansible在独立ESXi主机上创建VM。
Can I manage guest VMs in vSphere free using Ansible without vCenter?
然而,我在尝试运行剧本时遇到了错误 请指教
Error
[Parameter Error]: 'host' should be a string with the ESX/VC url
以下是剧本内容
---
- hosts: localhost
connection: local
gather_facts: no
vars_prompt:
- name: myuser
prompt: Enter the UserName
private: no
- name: mypass
prompt: Enter the Password
- name: vc_name
prompt: Enter the vCenter/ESXi HostName
private: no
- name: guest_name
prompt: Enter the Guest VM Name
private: no
remote_user: root
tasks:
- name: Create a VM
delegate_to: localhost
vsphere_guest:
# vcenter_hostname: '{{vc_name}}'
esxi:
datacenter: ha-datacenter
hostname: '{{vc_name}}'
username: '{{myuser}}'
password: '{{mypass}}'
validate_certs: no
guest: '{{guest_name}}'
state: powered_on
vm_extra_config:
vcpu.hotadd: yes
mem.hotadd: yes
notes: This is a test VM created using Ansible
vm_disk:
disk1:
size_gb: 100
type: thin
datastore: datastore1
vm_nic:
nic1:
type: vmxnet3
network: VM Network
network_type: standard
vm_hardware:
memory_mb: 2048
num_cpus: 2
osid: rhel6_64Guest
scsi: paravirtual
vm_cdrom:
type: "iso"
iso_path: "iso/rhel6.iso"
输出
Wed Jul 26 05:35:36 ansible@ansible-2:~/vmware$ ansible-playbook vmcreate.yml
Enter the UserName: root
Enter the Password:
Enter the vCenter/ESXi HostName: 10.1.1.1
Enter the Guest VM Name: ansible-test-vm
PLAY [localhost] ***************************************************************
TASK [Create a VM] *************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: pysphere.resources.vi_exception.VIException: [Parameter Error]: 'host' should be a string with the ESX/VC url.
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_SE0C2e/ansible_module_vsphere_guest.py\", line 1879, in <module>\n main()\n File \"/tmp/ansible_SE0C2e/ansible_module_vsphere_guest.py\", line 1748, in main\n viserver.connect(vcenter_hostname, username, password)\n File \"/usr/lib/python2.6/site-packages/pysphere/vi_server.py\", line 71, in connect\n ,FaultTypes.PARAMETER_ERROR)\npysphere.resources.vi_exception.VIException: [Parameter Error]: 'host' should be a string with the ESX/VC url.\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
NO MORE HOSTS LEFT *************************************************************
[WARNING]: Could not create retry file 'vmcreate.retry'. [Errno 2] No such file or directory: ''
PLAY RECAP *********************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1
Wed Jul 26 05:35:58 ansible@ansible-2:~/vmware$
答案 0 :(得分:0)
评论中的回答:
为什么
vcenter_hostname
被注释掉了?
-
这是问题,而不是ip我给了esxi的主机名并且它起作用了