我尝试通过 Ansible 部署 VMWare 客户机。不幸的是
ansible-playbook -i inventory.local vmware.yml
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [vmcenter00]
ok: [127.0.0.1]
TASK: [vsphere_guest ] ********************************************************
failed: [127.0.0.1] => {"failed": true, "parsed": false}
Traceback (most recent call last):
File "/Users/some_user/.ansible/tmp/ansible-tmp-1447432699.52-19521550866442/vsphere_guest", line 2936, in <module>
main()
File "/Users/some_user/.ansible/tmp/ansible-tmp-1447432699.52-19521550866442/vsphere_guest", line 1207, in main
viserver.connect(vcenter_hostname, username, password)
File "/Library/Python/2.7/site-packages/pysphere/vi_server.py", line 101, in connect
request)._returnval
File "/Library/Python/2.7/site-packages/pysphere/resources/VimService_services.py", line 2170, in RetrieveServiceContent
self.binding.Send(None, None, request, soapaction="urn:vim25/5.0", **kw)
File "/Library/Python/2.7/site-packages/pysphere/ZSI/client.py", line 295, in Send
self.local.h.connect()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1274, in connect
server_hostname=server_hostname)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 352, in wrap_socket
_context=self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 579, in __init__
self.do_handshake()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 808, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/some_user/vmware.retry
127.0.0.1 : ok=1 changed=0 unreachable=0 failed=1
vmcenter00 : ok=1 changed=0 unreachable=0 failed=0
您应该知道的事情。
我运行的是 OS X 10.11。我有 ansible 1.9.3 我有 pysphere (0.1.7) 输出:
python -c 'import ssl; print(ssl.OPENSSL_VERSION)'
OpenSSL 0.9.8zg 14 July 2015...
我这里遗漏了什么吗?
答案1
由于 SSL 证书验证失败,任务失败。在 Ansible 版本中,2.1
validate_certs
已添加到虚拟机
验证 SSL 证书。请注意,如果在没有 SSLContext 支持的 Python 上运行(通常 Python < 2.7.9),则必须将其设置为 no,因为 pysphere 不支持在较旧的 Python 上验证证书。在 2.1 之前,此模块将始终在 Python >= 2.7.9 上验证,而从不在 Python <= 2.7.8 上验证。
validate_certs: no
因此,只要您可以使用 Ansible 版本 >= 2.1 和 Python 版本 >= 2.7.9,设置就应该可以解决这个问题
答案2
解决方法:在以下两行中添加/Library/Python/2.7/site-packages/pysphere/vi_server.py
import ssl
ssl._create_default_https_context = ssl._create_unverified_context