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

**URL:** <https://forum.ansible.com/t/error-while-creating-vm-using-ansible-in-vshpere-must-call-connect-before-invoking-this-method/18284>\
**Category:** Ansible Project\
**Created:** [May 21, 2015, 5:44pm UTC](https://forum.ansible.com/t/error-while-creating-vm-using-ansible-in-vshpere-must-call-connect-before-invoking-this-method/18284 "2015-05-21T17:44:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarun\_emany](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@tarun\_emany](https://forum.ansible.com/u/tarun_emany)\
**Post date:** [May 21, 2015, 5:44pm UTC](https://forum.ansible.com/t/error-while-creating-vm-using-ansible-in-vshpere-must-call-connect-before-invoking-this-method/18284/1 "2015-05-21T17:44:47Z")

</div>

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
