Linux 如何使用vsphere_来宾Ansible模块在独立ESXi主机上创建VM

Linux 如何使用vsphere_来宾Ansible模块在独立ESXi主机上创建VM,linux,ansible,esxi,Linux,Ansible,Esxi,我正在尝试使用ansible playbook在独立的ESXi主机上创建VM。 我在下面的链接中看到,我们可以使用“ha数据中心”作为数据中心名称,使ansible在独立ESXi主机上创建VM 但是,我在尝试运行剧本时出现以下错误 请告知 Error [Parameter Error]: 'host' should be a string with the ESX/VC url 以下是剧本的内容 --- - hosts: localhost connection: local gat

我正在尝试使用ansible playbook在独立的ESXi主机上创建VM。 我在下面的链接中看到,我们可以使用“ha数据中心”作为数据中心名称,使ansible在独立ESXi主机上创建VM

但是,我在尝试运行剧本时出现以下错误 请告知

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$
Wed Jul 26 05:35:36ansible@ansible-2:~/vmware$ansible playbook vmcreate.yml
输入用户名:root
输入密码:
输入vCenter/ESXi主机名:10.1.1.1
输入来宾虚拟机名称:ansible测试虚拟机
播放[本地主机]***************************************************************
任务[创建虚拟机]*************************************************************
任务执行期间发生异常。要查看完整的回溯,请使用-vvv。错误是:pysphere.resources.vi_exception.vieexception:[参数错误]:“主机”应该是带有ESX/VC url的字符串。
致命:[localhost->localhost]:失败!=>{“changed”:false,“failed”:true,“module_stderr”:“Traceback(最近一次调用):\n File\”/tmp/ansible_SE0C2e/ansible_module_vsphere_guest.py\”,第1879行,在\n main()\n File\“/tmp/ansible_SE0C2e/ansible_module_vsphere_guest.py\”,第1748行,在main\n viserver.connect中(vcenter\u主机名、用户名、密码)\n File\”/usr/lib/python2.6/site packages/pysphere/vi_server.py\”,第71行,在connect\n中,FaultTypes.PARAMETER\u ERROR)\npysphere.resources.vi_exception.vieexception:[参数错误]:“host”应该是一个带有ESX/VC url的字符串。\n,“module_stdout”:“msg”:“module FAILURE”,“parsed”:false}
没有更多的主人了*************************************************************
[警告]:无法创建重试文件“vmcreate.retry”。[Errno 2]没有这样的文件或目录:“”
重演*********************************************************************
本地主机:确定=0更改=0无法访问=0失败=1
星期三7月26日05:35:58ansible@ansible-2:~/vmware$

从评论中回答:

为什么
vcenter\u主机名
被注释掉

-

这就是问题所在,我给出了esxi的主机名,而不是ip,它起了作用


评论的答复:

为什么
vcenter\u主机名
被注释掉

-

这就是问题所在,我给出了esxi的主机名,而不是ip,它起了作用


剧本内容的格式更好。您还可以设置代码块的格式,请参见我的编辑。为什么
vcenter\u主机名
被注释掉了?您好,这就是问题所在。我输入的是vcenter_主机名,而不是ip,我给出了esxi的主机名,它在通过Ansible部署虚拟机后工作如何登录虚拟机?我的意思是哪个用户和密码?剧本内容的格式更好。您还可以设置代码块的格式,请参见我的编辑。为什么
vcenter\u主机名
被注释掉了?您好,这就是问题所在。我输入的是vcenter_主机名,而不是ip,我给出了esxi的主机名,它在通过Ansible部署虚拟机后工作如何登录虚拟机?我是说哪个用户和密码?