# Create VM from template using vsphere\_guest module

**URL:** <https://forum.ansible.com/t/create-vm-from-template-using-vsphere-guest-module/23413>\
**Category:** Ansible Project\
**Created:** [January 9, 2017, 10:13pm UTC](https://forum.ansible.com/t/create-vm-from-template-using-vsphere-guest-module/23413 "2017-01-09T22:13:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Williams1](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@Robert\_Williams1](https://forum.ansible.com/u/Robert_Williams1)\
**Post date:** [January 9, 2017, 10:13pm UTC](https://forum.ansible.com/t/create-vm-from-template-using-vsphere-guest-module/23413/1 "2017-01-09T22:13:29Z")

</div>

Hello, I am new to Ansible and am having trouble spinning up a vm from a template using Ansible. I am unsure on what to put for “hosts” in my playbook. Should this be the vcenter hostname , vsphere hostname or something else? Any help is appreciated. Thanks in advance.

**PlayBook**

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [January 10, 2017, 10:23pm UTC](https://forum.ansible.com/t/create-vm-from-template-using-vsphere-guest-module/23413/2 "2017-01-10T22:23:59Z")

</div>

In this case you can probably just use

hosts: localhost

because vsphere\_guest will be using an api to talk to your vcenter.

By the way, there is a lot of development work going on around the vmware\_guest module at the moment. If you can test it out on latest development version of ansible, now would be a good time to report any issues.

Jon

---

<div class="post-metadata">

**Author:** ![Robert\_Williams1](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@Robert\_Williams1](https://forum.ansible.com/u/Robert_Williams1)\
**Post date:** [January 11, 2017, 8:09pm UTC](https://forum.ansible.com/t/create-vm-from-template-using-vsphere-guest-module/23413/3 "2017-01-11T20:09:04Z")

</div>

I tried adding local but that did not help. Here is the output:

Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: create\_appVCLOUD.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
1 plays in create\_appVCLOUD.yml

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

---

<div class="post-metadata">

**Author:** ![Robert\_Williams1](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@Robert\_Williams1](https://forum.ansible.com/u/Robert_Williams1)\
**Post date:** [January 11, 2017, 8:14pm UTC](https://forum.ansible.com/t/create-vm-from-template-using-vsphere-guest-module/23413/4 "2017-01-11T20:14:08Z")

</div>

Here is the error message when I use localhost in the playbook.

**ERROR MESSAGE**

Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: create\_appVCLOUD.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
1 plays in create\_appVCLOUD.yml

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [vsphere\_guest] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /etc/ansible/create\_appVCLOUD.yml:6  
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/cloud/vmware/vsphere\_guest.py  
\<127.0.0.1\> ESTABLISH LOCAL CONNECTION FOR USER: root  
\<127.0.0.1\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo $HOME/.ansible/tmp/ansible-tmp-1484165467.41-270348352264162`” && echo ansible-tmp-1484165467.41-270348352264162=“`echo $HOME/.ansible/tmp/ansible-tmp-1484165467.41-270348352264162`” ) && sleep 0’  
\<127.0.0.1\> PUT /tmp/tmp\_bDCQ3 TO /root/.ansible/tmp/ansible-tmp-1484165467.41-270348352264162/vsphere\_guest.py  
\<127.0.0.1\> EXEC /bin/sh -c ‘chmod u+x /root/.ansible/tmp/ansible-tmp-1484165467.41-270348352264162/ /root/.ansible/tmp/ansible-tmp-1484165467.41-270348352264162/vsphere\_guest.py && sleep 0’  
\<127.0.0.1\> EXEC /bin/sh -c ‘/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1484165467.41-270348352264162/vsphere\_guest.py; rm -rf “/root/.ansible/tmp/ansible-tmp-1484165467.41-270348352264162/” \> /dev/null 2\>&1 && sleep 0’  
An exception occurred during task execution. The full traceback is:  
Traceback (most recent call last):  
File “/tmp/ansible\_vw2rQu/ansible\_module\_vsphere\_guest.py”, line 1909, in   
main()  
File “/tmp/ansible\_vw2rQu/ansible\_module\_vsphere\_guest.py”, line 1776, in main  
viserver.connect(vcenter\_hostname, username, password)  
File “build/bdist.linux-x86\_64/egg/pysphere/vi\_server.py”, line 101, in connect  
File “build/bdist.linux-x86\_64/egg/pysphere/resources/VimService\_services.py”, line 2170, in RetrieveServiceContent  
File “build/bdist.linux-x86\_64/egg/pysphere/ZSI/client.py”, line 295, in Send  
File “/usr/lib64/python2.7/httplib.py”, line 1227, in connect  
HTTPConnection.connect(self)  
File “/usr/lib64/python2.7/httplib.py”, line 807, in connect  
self.timeout, self.source\_address)  
File “/usr/lib64/python2.7/socket.py”, line 571, in create\_connection  
raise err  
socket.error: [Errno 111] Connection refused  
fatal: [localhost]: FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“invocation”: {  
“module\_name”: “vsphere\_guest”  
},  
“module\_stderr”: “Traceback (most recent call last):\n File "/tmp/ansible\_vw2rQu/ansible\_module\_vsphere\_guest.py", line 1909, in \n main()\n File "/tmp/ansible\_vw2rQu/ansible\_module\_vsphere\_guest.py", line 1776, in main\n viserver.connect(vcenter\_hostname, username, password)\n File "build/bdist.linux-x86\_64/egg/pysphere/vi\_server.py", line 101, in connect\n File "build/bdist.linux-x86\_64/egg/pysphere/resources/VimService\_services.py", line 2170, in RetrieveServiceContent\n File "build/bdist.linux-x86\_64/egg/pysphere/ZSI/client.py", line 295, in Send\n File "/usr/lib64/python2.7/httplib.py", line 1227, in connect\n HTTPConnection.connect(self)\n File "/usr/lib64/python2.7/httplib.py", line 807, in connect\n self.timeout, self.source\_address)\n File "/usr/lib64/python2.7/socket.py", line 571, in create\_connection\n raise err\nsocket.error: [Errno 111] Connection refused\n”,  
“module\_stdout”: “”,  
“msg”: “MODULE FAILURE”  
}  
to retry, use: --limit @/etc/ansible/create\_appVCLOUD.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=0 changed=0 unreachable=0 failed=1
