mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
VMware: Fix vcenter connection error message (#33621)
This fix make error message easily understable which is provided by vcenter or ESXi server. Fixes: #24672 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
1b5c4b72bd
commit
a28eb94f1a
1 changed files with 9 additions and 12 deletions
|
@ -299,6 +299,7 @@ EXAMPLES = '''
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import ssl
|
import ssl
|
||||||
|
import socket
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
HAS_PYSPHERE = False
|
HAS_PYSPHERE = False
|
||||||
|
@ -1797,21 +1798,17 @@ def main():
|
||||||
module.fail_json(msg='pysphere does not support verifying certificates with python < 2.7.9. Either update python or set '
|
module.fail_json(msg='pysphere does not support verifying certificates with python < 2.7.9. Either update python or set '
|
||||||
'validate_certs=False on the task')
|
'validate_certs=False on the task')
|
||||||
|
|
||||||
|
if not validate_certs:
|
||||||
|
ssl._create_default_https_context = ssl._create_unverified_context
|
||||||
|
|
||||||
try:
|
try:
|
||||||
viserver.connect(vcenter_hostname, username, password)
|
viserver.connect(vcenter_hostname, username, password)
|
||||||
except ssl.SSLError as sslerr:
|
except ssl.SSLError as sslerr:
|
||||||
if '[SSL: CERTIFICATE_VERIFY_FAILED]' in sslerr.strerror:
|
module.fail_json(msg='Unable to validate the certificate of the vcenter hostname %s. Due to %s' % (vcenter_hostname, sslerr))
|
||||||
if not validate_certs:
|
except socket.gaierror as err:
|
||||||
ssl._create_default_https_context
|
module.fail_json(msg="Unable to resolve name for vcenter hostname: %s. Due to %s" % (vcenter_hostname, to_native(err)))
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context
|
except (TypeError, VIApiException) as err:
|
||||||
viserver.connect(vcenter_hostname, username, password)
|
module.fail_json(msg="Cannot connect to %s: %s" % (vcenter_hostname, to_native(err)),
|
||||||
else:
|
|
||||||
module.fail_json(msg='Unable to validate the certificate of the vcenter host %s' % vcenter_hostname)
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
except VIApiException as err:
|
|
||||||
module.fail_json(msg="Cannot connect to %s: %s" %
|
|
||||||
(vcenter_hostname, to_native(err)),
|
|
||||||
exception=traceback.format_exc())
|
exception=traceback.format_exc())
|
||||||
|
|
||||||
# Check if the VM exists before continuing
|
# Check if the VM exists before continuing
|
||||||
|
|
Loading…
Add table
Reference in a new issue