# Error in Deploying Virtual Machines to vCenter with Ansible | Must call 'connect' before invoking this method

**URL:** <https://forum.ansible.com/t/error-in-deploying-virtual-machines-to-vcenter-with-ansible-must-call-connect-before-invoking-this-method/18274>\
**Category:** Ansible Project\
**Created:** [May 21, 2015, 2:57am UTC](https://forum.ansible.com/t/error-in-deploying-virtual-machines-to-vcenter-with-ansible-must-call-connect-before-invoking-this-method/18274 "2015-05-21T02:57:17Z")\
**Posts on this page:** 4\
**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, 2:57am UTC](https://forum.ansible.com/t/error-in-deploying-virtual-machines-to-vcenter-with-ansible-must-call-connect-before-invoking-this-method/18274/1 "2015-05-21T02:57:17Z")

</div>

Hi,

While deploying new VM to vCenter using Ansible playbook I am getting the following error.

failed: [127.0.0.1] =\> {“failed”: true, “parsed”: false}  
Traceback (most recent call last):  
File “/.ansible/tmp/ansible-tmp-1432176296.75-239675909842816/vsphere\_guest”, line 2923, in   
main()  
File “/.ansible/tmp/ansible-tmp-1432176296.75-239675909842816/vsphere\_guest”, line 1312, in main  
state=state  
File “/.ansible/tmp/ansible-tmp-1432176296.75-239675909842816/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

I have installed pysphere and created following yml and tried execution.

My playbook.yml is

- hosts: 127.0.0.1  
connection: local  
user: root  
sudo: false  
gather\_facts: false  
serial: 1  
tasks:
- vsphere\_guest:  
vcenter\_hostname: xxxxxx  
username: xxxxx  
password: xxxx  
guest: SampleVM  
state: powered\_on  
vm\_extra\_config:  
vcpu.hotadd: yes  
mem.hotadd: yes  
notes: This is a test VM  
vm\_disk:  
disk1:  
size\_gb: 10  
type: thin  
datastore: xxxxxx  
vm\_nic:  
nic1:  
type: vmxnet3  
network: vm  
network\_type: standard  
vm\_hardware:  
memory\_mb: 1024  
num\_cpus: 1  
osid: UbuntuLinux  
scsi: paravirtual  
esxi:  
datacenter: xxxxxx  
hostname: xxxxx

Please help me out.

---

<div class="post-metadata">

**Author:** ![mhael](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mhael](https://forum.ansible.com/u/mhael)\
**Post date:** [May 21, 2015, 11:26pm UTC](https://forum.ansible.com/t/error-in-deploying-virtual-machines-to-vcenter-with-ansible-must-call-connect-before-invoking-this-method/18274/2 "2015-05-21T23:26:45Z")

</div>

Hi Tarun,

Most probably you have some issue with provided configuration parameters for VM. From my experience, “Must call ‘connect’ before invoking this method” is a generic error reported by vsphere\_guest module when VMware is unable to create the VM.  
To see what exactly is wrong - connect to your target vCenter (or ESXi) server with vSphere client and check the tasks status panel when running the playbook. The error message there usually shows a clue on what item in VM configuration causes error.

---

<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, 11:30pm UTC](https://forum.ansible.com/t/error-in-deploying-virtual-machines-to-vcenter-with-ansible-must-call-connect-before-invoking-this-method/18274/3 "2015-05-21T23:30:39Z")

</div>

Thanks Mikhail,

It was a configuration issue.The osid is given wrong. It worked after changing to ubuntu64Guest.

---

<div class="post-metadata">

**Author:** ![Gallo](https://avatars.discourse-cdn.com/v4/letter/g/cab0a1/32.png) [@Gallo](https://forum.ansible.com/u/Gallo)\
**Post date:** [August 18, 2016, 8:29pm UTC](https://forum.ansible.com/t/error-in-deploying-virtual-machines-to-vcenter-with-ansible-must-call-connect-before-invoking-this-method/18274/4 "2016-08-18T20:29:23Z")

</div>

Yep, had the same problem. Same solution the “osid”
