title: How to create VM on Standalone ESXi hosts using vsphere_guest Ansible Module
body: <p>I am trying to create a VM on a standalone ESXi host using ansible playbook.
  I saw in the following link that we can use "ha-datacenter" as the datacenter name to make ansible create VM on standalone ESXi host.</p>
  
  <p><a href="https://stackoverflow.com/questions/43420285/can-i-manage-guest-vms-in-vsphere-free-using-ansible-without-vcenter">Can I manage guest VMs in vSphere free using Ansible without vCenter?</a></p>
  
  <p>I am however getting following error while trying to run the playbook
  Please advise</p>
  
  <pre><code>Error
  [Parameter Error]: 'host' should be a string with the ESX/VC url
  </code></pre>
  
  <p>Following are playbook contents</p>
  
  <pre><code>---
  - 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"
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>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 -&gt; localhost]: FAILED! =&gt; {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_SE0C2e/ansible_module_vsphere_guest.py\", line 1879, in &lt;module&gt;\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$
  </code></pre>