Error while creating VM using ansible in vShpere | Must call 'connect' before invoking this method

Hi,

I am trying to create VM using ansible playbook.

  • hosts: 127.0.0.1
    connection: local
    user: root
    sudo: false
    gather_facts: false
    serial: 1

tasks:

  • vsphere_guest:
    vcenter_hostname: ‘10.39.1.59’
    username: ‘xxxx’
    password: ‘xxxx’
    guest: ‘newTestVM’
    state: powered_on
    vm_disk:
    disk1:
    size_gb: 10
    type: thin
    datastore: 10_39_1_59_datastore1
    vm_nic:
    nic1:
    type: vmxnet3
    network: vm
    network_type: standard
    vm_hardware:
    memory_mb: 1024
    num_cpus: 1
    osid: UbuntuLinux
    scsi: paravirtual
    esxi:
    datacenter: ha-datacenter
    hostname: xxxxx

While executing this playbook I am gettting following error. I am using python 2.7.6

failed: [127.0.0.1] => {“failed”: true, “parsed”: false}
Traceback (most recent call last):
File “/home/tarun/.ansible/tmp/ansible-tmp-1432229782.37-105411516106078/vsphere_guest”, line 2923, in
main()
File “/home/tarun/.ansible/tmp/ansible-tmp-1432229782.37-105411516106078/vsphere_guest”, line 1312, in main
state=state
File “/home/tarun/.ansible/tmp/ansible-tmp-1432229782.37-105411516106078/vsphere_guest”, line 901, in create_vm
task.get_error_message())
File “/usr/local/lib/python2.7/dist-packages/pysphere/vi_task.py”, line 82, in get_error_message
self.__poll_task_info()
File “/usr/local/lib/python2.7/dist-packages/pysphere/vi_task.py”, line 120, in __poll_task_info
raise e
pysphere.resources.vi_exception.VIException: [Not Connected]: Must call ‘connect’ before invoking this method

FATAL: all hosts have already failed – aborting

Please help me with this…

Thanks