【发布时间】:2018-01-01 19:29:39
【问题描述】:
我正在尝试使用 ansible playbook 在独立 ESXi 主机上创建 VM。 我在下面的链接中看到我们可以使用“ha-datacenter”作为数据中心名称来在独立的 ESXi 主机上创建虚拟机。
Can I manage guest VMs in vSphere free using Ansible without vCenter?
但是,我在尝试运行 playbook 时遇到以下错误 请指教
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$
【问题讨论】:
-
Playbook 内容格式更好。 pastebin.com/sQ2XMBXe
-
您也可以在 SO 上格式化代码块,请参阅我的编辑。为什么
vcenter_hostname被注释掉了? -
嗨康斯坦丁,这就是问题所在。我收入是 vcenter_hostname 而不是 ip 我给了 esxi 的主机名,它工作
-
通过Ansible部署VM后如何登录vm?我的意思是哪个用户和密码?