After you deploy the vSAN Witness Appliance, you must add it to vCenter Server to serve as the witness host in your stretched cluster or two-host configuration. The witness host must not be part of the vSAN cluster.

You can use the vSphere Client to add the vSAN Witness Appliance as a host to vCenter Server.

To add the host programmatically, first create a function that adds the vSAN Witness Appliance as a host in vCenter Server.

def AddHost(host, user='root', pwd=None, dcRef=None, si=None, sslThumbprint=None, port=443):
    ''' Add a host to a data center Returns a host system '''


cnxSpec = vim.HostConnectSpec(
    force=True, hostName=host, port=port, userName=user, password=pwd, vmFolder=dcRef.vmFolder)
if sslThumbprint:
    cnxSpec.sslThumbprint = sslThumbprint
hostParent = dcRef.hostFolder
try:
    task = hostParent.AddStandaloneHost(addConnected=True, spec=cnxSpec)
vsanapiutils.WaitForTasks([task], si)
return getHostSystem(host, dcRef, si)
except vim.SSLVerifyFault as e:
# By catching this exception, you do not need to input the host's thumb print of the SSL certificate
# The following script does this automatically.
cnxSpec.sslThumbprint = e.thumbprint
task = hostParent.AddStandaloneHost(addConnected=True, spec=cnxSpec)
vsanapiutils.WaitForTasks([task], si)
return getHostSystem(host, dcRef, si)
except vim.DuplicateName as e:
raise Exception("AddHost: ESX host %s has already been added to VC." % host)

Then add the host by calling the function.

print 'Add witness host {} to datacenter {}'.format(witnessVm.name,
                                                    args.witnessdc)
dcRef = searchIndex.FindChild(
    entity=si.content.rootFolder, name=args.witnessdc)
witnessHost = AddHost(
    witnessVm.guest.ipAddress, pwd=args.vmpassword, dcRef=dcRef, si=si)