From a381c1bbd671172834015c62f50c7e7225efb827 Mon Sep 17 00:00:00 2001 From: Kamil Szczygiel Date: Wed, 27 Jan 2016 20:41:28 +0100 Subject: [PATCH] added skip_ssl argument for VMware module to skip SSL verification (required when using self signed certificates) --- lib/ansible/module_utils/vmware.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/vmware.py b/lib/ansible/module_utils/vmware.py index 6eb612de744..ca0440a26c3 100644 --- a/lib/ansible/module_utils/vmware.py +++ b/lib/ansible/module_utils/vmware.py @@ -21,6 +21,7 @@ try: import atexit import time + import ssl # requests is required for exception handling of the ConnectionError import requests from pyVim import connect @@ -104,6 +105,7 @@ def vmware_argument_spec(): hostname=dict(type='str', required=True), username=dict(type='str', aliases=['user', 'admin'], required=True), password=dict(type='str', aliases=['pass', 'pwd'], required=True, no_log=True), + skip_ssl=dict(type='bool', required=False, default=False), ) @@ -112,8 +114,15 @@ def connect_to_api(module, disconnect_atexit=True): hostname = module.params['hostname'] username = module.params['username'] password = module.params['password'] + skip_ssl = module.params['skip_ssl'] + try: - service_instance = connect.SmartConnect(host=hostname, user=username, pwd=password) + if skip_ssl: + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + context.verify_mode = ssl.CERT_NONE + service_instance = connect.SmartConnect(host=hostname, user=username, pwd=password, sslContext=context) + else: + service_instance = connect.SmartConnect(host=hostname, user=username, pwd=password) # Disabling atexit should be used in special cases only. # Such as IP change of the ESXi host which removes the connection anyway.