summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorGonéri Le Bouder <goneri@lebouder.net>2019-05-30 11:17:14 -0400
committerGonéri Le Bouder <goneri@lebouder.net>2019-07-26 10:35:12 +0200
commit06c7b87613cc24b100a10074746d39e934eccfa7 (patch)
treebff2480c7a5a998fee8348575000bf8b6b682411 /contrib
parentd82446652fcac3d039bb4485865ce5f9a162e859 (diff)
downloadansible-06c7b87613cc24b100a10074746d39e934eccfa7.tar.gz
vmware_inventory: do not ignore validate_certs
Python 2.7.9 < does not have the `ssl.SSLContext` attribute. If `validate_certs` is `True`, we cannot validate the SSL connection, and we need to raise an error.
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/inventory/vmware_inventory.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/contrib/inventory/vmware_inventory.py b/contrib/inventory/vmware_inventory.py
index e6407bcbce..183b9a19b0 100755
--- a/contrib/inventory/vmware_inventory.py
+++ b/contrib/inventory/vmware_inventory.py
@@ -344,10 +344,22 @@ class VMWareInventory(object):
'pwd': self.password,
'port': int(self.port)}
- if hasattr(ssl, 'SSLContext') and not self.validate_certs:
+ if self.validate_certs and hasattr(ssl, 'SSLContext'):
+ context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ context.verify_mode = ssl.CERT_REQUIRED
+ context.check_hostname = True
+ kwargs['sslContext'] = context
+ elif self.validate_certs and not hasattr(ssl, 'SSLContext'):
+ sys.exit('pyVim does not support changing verification mode with python < 2.7.9. Either update '
+ 'python or use validate_certs=false.')
+ elif not self.validate_certs and hasattr(ssl, 'SSLContext'):
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.verify_mode = ssl.CERT_NONE
+ context.check_hostname = False
kwargs['sslContext'] = context
+ elif not self.validate_certs and not hasattr(ssl, 'SSLContext'):
+ # Python 2.7.9 < or RHEL/CentOS 7.4 <
+ pass
return self._get_instances(kwargs)