Host应该是ansible中的字符串错误

Host should be a string error in ansible

这是我在 运行 此代码时遇到的错误。

[my-host]
 19.3.112.97  ansible_ssh_pass=mypass ansible_ssh_user=root

剧本是

---
- hosts: localhost
  connection: local
  tasks:
    - vsphere_guest:
        guest: newvm001
        vmware_guest_facts: yes

错误:

An exception occurred during task execution. The full traceback is: Traceback (most recent call last): File "/var/folders/zt/s5ykx9_n4y9611h_k_gj_vx00000gn/T/ansible_vYePRK/ansible_module_vsphere_guest.py", line 1879, in main() File "/var/folders/zt/s5ykx9_n4y9611h_k_gj_vx00000gn/T/ansible_vYePRK/ansible_module_vsphere_guest.py", line 1748, in main viserver.connect(vcenter_hostname, username, password) File "/Library/Python/2.7/site-packages/pysphere/vi_server.py", line 71, in connect ,FaultTypes.PARAMETER_ERROR) pysphere.resources.vi_exception.VIException: [Parameter Error]: 'host' should be a string with the ESX/VC url.

fatal: [9.1.142.86]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "vsphere_guest"}, "module_stderr": "Traceback (most recent call last):\n File \"/var/folders/zt/s5ykx9_n4y9611h_k_gj_vx00000gn/T/ansible_vYePRK/ansible_module_vsphere_guest.py\", line 1879, in \n main()\n File \"/var/folders/zt/s5ykx9_n4y9611h_k_gj_vx00000gn/T/ansible_vYePRK/ansible_module_vsphere_guest.py\", line 1748, in main\n viserver.connect(vcenter_hostname, username, password)\n File \"/Library/Python/2.7/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}

为什么会出现此错误?

您目前正在向 vsphere_guestguestvmware_guest_facts 提供两个参数。但是,the documentation 列出了更多需要的参数:

  • 密码
  • 用户名
  • vcenter_hostname

如果我不得不猜测,vcenter_hostname 默认为 None(Python 的 null 等价物),因此期望它是 URI 字符串的代码会抛出异常你看那里。