# Ansible 2.0 VMWare modules

**URL:** <https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [January 13, 2016, 5:54pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202 "2016-01-13T17:54:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Larry\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Larry\_Smith1](https://forum.ansible.com/u/Larry_Smith1)\
**Post date:** [January 13, 2016, 5:54pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/1 "2016-01-13T17:54:29Z")

</div>

Just getting started messing with these new 2.0 VMWare modules and seem to be stuck on an SSL error. Anyone know how to get around this? Any info would be much appreciated.

fatal: [localhost → localhost]: FAILED! =\> {“apierror”: “[Errno 1] \_ssl.c:510: error:14090086:SSL routines:SSL3\_GET\_SERVER\_CERTIFICATE:certificate verify failed”, “changed”: false, “failed”: true, “msg”: “Unable to connect to vCenter or ESXi API on TCP/443.”}

---

<div class="post-metadata">

**Author:** ![Marcus\_Franke](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@Marcus\_Franke](https://forum.ansible.com/u/Marcus_Franke)\
**Post date:** [January 14, 2016, 8:35am UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/2 "2016-01-14T08:35:25Z")

</div>

Hi,

by default VMware uses a self signed certificate for the vcenter web interface.

You could change this against an official one with a trust anchor your system can verify or configure your play not to verify the certificate. If that is possible, never used that module myself.

Regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![Larry\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Larry\_Smith1](https://forum.ansible.com/u/Larry_Smith1)\
**Post date:** [January 15, 2016, 6:09am UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/3 "2016-01-15T06:09:03Z")

</div>

Yup. I know about the default self-signed but I would assume that either pyvmomi module and/or the Ansible documentation might explain on how to get around this error. Especially just for testing purposes. Thanks for the reply though.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 15, 2016, 6:25am UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/4 "2016-01-15T06:25:37Z")

</div>

we should add validate\_certs=yes|no option as we do in other modules.

---

<div class="post-metadata">

**Author:** ![Larry\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Larry\_Smith1](https://forum.ansible.com/u/Larry_Smith1)\
**Post date:** [January 15, 2016, 4:31pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/5 "2016-01-15T16:31:37Z")

</div>

Absolutely that would be the way to do this.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 15, 2016, 4:35pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/6 "2016-01-15T16:35:43Z")

</div>

vsphere\_copy already supports this, though we really should do it in  
the module\_utils shared code

---

<div class="post-metadata">

**Author:** ![Kesten\_Broughton](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@Kesten\_Broughton](https://forum.ansible.com/u/Kesten_Broughton)\
**Post date:** [January 15, 2016, 5:30pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/7 "2016-01-15T17:30:23Z")

</div>

vsphere\_guest is based on pysphere and the ansible-extra-modules vmware modules are based on psphere, (both of which are largely abandoned)  
but this PR for pyVmomi supported by VWmare should work.

> <https://github.com/vmware/pyvmomi-community-samples/pull/213/files>
>
> Adding option for not checking ssl certificates, useful for testing HVs with sel…f-signed certificates

A thing you could do, but shouldn’t do for security reasons is note from the error which site-packages directory it is failing at.  
Then add the following to the bottom of the sitecustomize.py file therein

import ssl

try:  
\_create\_unverified\_https\_context = ssl.\_create\_unverified\_context  
except AttributeError:

# Legacy Python that doesn’t verify HTTPS certificates by default

pass  
else:

# Handle target environment that doesn’t support HTTPS verification

ssl.\_create\_default\_https\_context = \_create\_unverified\_https\_context

---

<div class="post-metadata">

**Author:** ![cpaul](https://avatars.discourse-cdn.com/v4/letter/c/47e85d/32.png) [@cpaul](https://forum.ansible.com/u/cpaul)\
**Post date:** [January 15, 2016, 9:40pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/8 "2016-01-15T21:40:45Z")

</div>

I am currently testing a PR for module\_utils/vmware.py which adds ‘validate\_certs’ as an argument.

---

<div class="post-metadata">

**Author:** ![jess.males](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@jess.males](https://forum.ansible.com/u/jess.males)\
**Post date:** [January 22, 2016, 10:30pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/9 "2016-01-22T22:30:48Z")

</div>

I ran into a need for this today. How goes your testing? Need any help?

Thanks,

– Jess

---

<div class="post-metadata">

**Author:** ![Larry\_Smith](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@Larry\_Smith](https://forum.ansible.com/u/Larry_Smith)\
**Post date:** [January 26, 2016, 3:29am UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/10 "2016-01-26T03:29:32Z")

</div>

Awesome…Looking forward to the outcome…I really do not want to hack any python modules to make it work…But understand if that is the only way short-term.

---

<div class="post-metadata">

**Author:** ![Kesten\_Broughton](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@Kesten\_Broughton](https://forum.ansible.com/u/Kesten_Broughton)\
**Post date:** [January 26, 2016, 8:56pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/11 "2016-01-26T20:56:51Z")

</div>

Looking forward to this patch!

For those testing vmware, i’ve added a few features to vmware.py dynamic inventory which ec2.py inventory comes with but were sorely missing in vmware.py.  
instance\_filters and --refresh-cache. Plus a bug fix that allows cache\_dir to be found.

> <https://github.com/ansible/ansible/pull/14136>
>
> vmware.ini has the line
> \# cache\_dir = ~/.cache/ansible
> 
> However, the code that r…eads the cache\_dir does not expand the ~. Added os.path.expanduser to fix.
> 
> To make this dynamic inventory similar to ec2.py I added
> instance\_filters
> and a --refresh-cache flag.
> 
> To test, install jq. Customize your vmware.ini and source your vars into the shell environment.
> note '' is two single quotes in the lines below
> $ ./vmware.py | jq ''
> Note now long it takes
> $ ./vmware.py | jq '' 
> The second time should be much faster if you uncomment cache\_dir
> $ ./vmware.py --refresh-cache | jq ''
> This should return almost instantly

If anyone is interested, i also added some hacky tag support by parsing the guest name and searching for specific tags that can be set in vmware.ini  
Then guests with correct names will be put into ansible groups that can be mapped to roles in a vmware\_hosts file.

I will make a separate PR for this if folks are interested, but it’s sort of a hack until vsphere\_guest supports tags. Right now it suggests that it has ‘notes’ but none showed up for me.

def \_get\_vm\_info(self, vm, prefix=‘vmware’):  
‘’’  
Return a flattened dict with info about the given virtual machine.  
‘’’  
vm\_info = {  
‘name’: vm.name,  
}  
vm\_info[‘class\_tag’] = self.\_parse\_name\_for\_server\_class(vm.name)

def \_parse\_name\_for\_server\_class(self, guest\_name):  
‘’’  
This is a hack to get around lack of support for tags.

Embed the tag in the name and parse it to set the server class - worker, master, server  
Then map the simple group to the roles in the vmware\_inventory/vmware\_hosts file  
@param guest\_name: name of vmware guest instance. Corresponds to guest field in vsphere\_guest.  
‘’’

# this could probably be read in from vmware.ini file but fine for now

DEFINED\_SERVER\_CLASS\_TAGS = [‘master’, ‘server’, ‘worker’, ‘solutions’]

for class\_tag in DEFINED\_SERVER\_CLASS\_TAGS:  
if guest\_name.find(class\_tag) != -1:  
return class\_tag  
return None

at the bottom of  
def get\_inventory():

# Group by class\_tag

# vm can only be in one class

vm\_class\_tag = vm\_info.get(‘vmware\_class\_tag’, None)  
if vm\_class\_tag:  
self.\_add\_child(inv, vm\_group, ‘class\_tag’)  
self.\_add\_child(inv, ‘class\_tag’, vm\_class\_tag)  
self.\_add\_host(inv, vm\_class\_tag, vm.name)

---

<div class="post-metadata">

**Author:** ![kamil.szczygiel](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@kamil.szczygiel](https://forum.ansible.com/u/kamil.szczygiel)\
**Post date:** [January 27, 2016, 7:48pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/12 "2016-01-27T19:48:03Z")

</div>

I’ve added skip\_ssl argument to module\_utils/vmware.py. Perhaps that’s not the best implementation…

[https://github.com/kamsz/ansible](https://github.com/kamsz/ansible)

---

<div class="post-metadata">

**Author:** ![Jonathan\_Frappier](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@Jonathan\_Frappier](https://forum.ansible.com/u/Jonathan_Frappier)\
**Post date:** [February 15, 2016, 3:49pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/13 "2016-02-15T15:49:09Z")

</div>

Where do you suggest adding validate\_certs=false? It wasn’t obvious to me

---

<div class="post-metadata">

**Author:** ![Jonathan\_Frappier](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@Jonathan\_Frappier](https://forum.ansible.com/u/Jonathan_Frappier)\
**Post date:** [February 15, 2016, 3:54pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/14 "2016-02-15T15:54:46Z")

</div>

Where do you suggest adding validate\_certs=false?

---

<div class="post-metadata">

**Author:** ![kamil.szczygiel](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@kamil.szczygiel](https://forum.ansible.com/u/kamil.szczygiel)\
**Post date:** [February 15, 2016, 4:52pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/15 "2016-02-15T16:52:55Z")

</div>

My PR for validate\_certs was merged to the master branch ([https://github.com/ansible/ansible/pull/14261](https://github.com/ansible/ansible/pull/14261)). I suggest using devel, as it’s already reviewed and merged (add validate\_certs=false as param for the module you’re using)

---

<div class="post-metadata">

**Author:** ![Jonathan\_Frappier](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@Jonathan\_Frappier](https://forum.ansible.com/u/Jonathan_Frappier)\
**Post date:** [February 15, 2016, 5:08pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/16 "2016-02-15T17:08:33Z")

</div>

Curious if anyone else has had luck with this in devel? I get “unsupported parameter for module: validate\_certs”

- name: Add ESXi host to vCenter  
local\_action:  
module: vmware\_host  
hostname: “{{ vcenter }}”  
username: administrator@vsphere.local  
password: xxxx  
datacenter\_name: “{{ dc }}”  
cluster\_name: “{{ cl }}”  
esxi\_hostname: “{{ esxi }}”  
esxi\_username: xxxx  
esxi\_password: xxxx  
state: present  
validate\_certs: false

---

<div class="post-metadata">

**Author:** ![kamil.szczygiel](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@kamil.szczygiel](https://forum.ansible.com/u/kamil.szczygiel)\
**Post date:** [February 15, 2016, 5:16pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/17 "2016-02-15T17:16:01Z")

</div>

I’ve just cloned and installed from devel - works for me.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Frappier](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@Jonathan\_Frappier](https://forum.ansible.com/u/Jonathan_Frappier)\
**Post date:** [February 15, 2016, 5:17pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/18 "2016-02-15T17:17:58Z")

</div>

With VMware\_host or another module?

---

<div class="post-metadata">

**Author:** ![kamil.szczygiel](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@kamil.szczygiel](https://forum.ansible.com/u/kamil.szczygiel)\
**Post date:** [February 15, 2016, 5:19pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/19 "2016-02-15T17:19:55Z")

</div>

I’ve copied the playbook you’ve pasted, modified credentials and it works.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Frappier](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@Jonathan\_Frappier](https://forum.ansible.com/u/Jonathan_Frappier)\
**Post date:** [February 15, 2016, 5:31pm UTC](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202/20 "2016-02-15T17:31:59Z")

</div>

Thanks! Really appreciate it, I’ll poke at my local environment more.

[Next page](https://forum.ansible.com/t/ansible-2-0-vmware-modules/20202.md?page=2)
