Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMware: correct logic to pass ESXi SSL thumbprint #47600

Merged
merged 2 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ansible/module_utils/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@


class TaskError(Exception):
pass
def __init__(self, *args, **kwargs):
super(TaskError, self).__init__(*args, **kwargs)


def wait_for_task(task, max_backoff=64, timeout=3600):
Expand All @@ -56,12 +57,15 @@ def wait_for_task(task, max_backoff=64, timeout=3600):
return True, task.info.result
if task.info.state == vim.TaskInfo.State.error:
error_msg = task.info.error
host_thumbprint = None
try:
error_msg = error_msg.msg
if hasattr(task.info.error, 'thumbprint'):
host_thumbprint = task.info.error.thumbprint
except AttributeError:
pass
finally:
raise_from(TaskError(error_msg), task.info.error)
raise_from(TaskError(error_msg, host_thumbprint), task.info.error)
if task.info.state in [vim.TaskInfo.State.running, vim.TaskInfo.State.queued]:
sleep_time = min(2 ** failure_counter + randint(1, 1000) / 1000, max_backoff)
time.sleep(sleep_time)
Expand Down
8 changes: 6 additions & 2 deletions lib/ansible/modules/cloud/vmware/vmware_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ def add_host_to_vcenter(self):
return success, result
except TaskError as task_error_exception:
task_error = task_error_exception.args[0]
if self.esxi_ssl_thumbprint == '' and isinstance(task_error, vim.fault.SSLVerifyFault):
if len(task_error_exception.args) == 2:
host_thumbprint = task_error_exception.args[1]
else:
host_thumbprint = None
if self.esxi_ssl_thumbprint == '' and host_thumbprint:
# User has not specified SSL Thumbprint for ESXi host,
# try to grab it using SSLVerifyFault exception
host_connect_spec.sslThumbprint = task_error.thumbprint
host_connect_spec.sslThumbprint = host_thumbprint
else:
self.module.fail_json(msg="Failed to add host %s to vCenter: %s" % (self.esxi_hostname,
to_native(task_error)))
Expand Down