![Ansible SSL 証明書の検証に失敗しました](https://rvso.com/image/747324/Ansible%20SSL%20%E8%A8%BC%E6%98%8E%E6%9B%B8%E3%81%AE%E6%A4%9C%E8%A8%BC%E3%81%AB%E5%A4%B1%E6%95%97%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F.png)
Windowsホストを管理するためにAnsibleを設定しようとしています。ホストは内部CAから発行されたSSL証明書を使用します。指示に従ってWindowsホストを構成しました。ここしかし、モジュール win_ping を使用して接続しようとすると、次のメッセージが表示されます。
HTTPSConnectionPool(host='[email protected]', port=5986): Max retries exceeded with url: /wsman (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)'),))"
ポート 5986 で Windows ホストに接続すると、CA によって発行された証明書が使用されることを確認しました。また、hosts ファイルで変数として ansible_winrm_ca_trust_path を使用して CA 証明書を指定しようとしましたが、証明書が検証されません。hosts ファイルの内容は次のとおりです。
local:
control:
win_test:
hosts:
winhost.mydomain.local:
vars:
ansible_connection: winrm
ansible_user: [email protected]
ansible_password: "#######"
ansible_connection: winrm
ansible_winrm_transport: kerberos
ansible_winrm_ca_trust_path: /home/[email protected]/ansible/CA.cert
では、証明書の検証で何が間違っているのでしょうか? 参考までに、私は Python 2.7.5 で Ansible v2.9.2 を実行しています。
アップデート: Python3 に切り替えましたが、同じエラーが発生します。エラーの詳細出力は次のとおりです。
ansible 2.9.2
config file = /home/[email protected]/ansible/ansible.cfg
configured module search path = ['/home/[email protected]/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/[email protected]/.local/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Aug 7 2019, 17:28:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /home/[email protected]/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /home/[email protected]/ansible/hosts as it did not pass its verify_file() method
script declined parsing /home/[email protected]/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /home/[email protected]/ansible/hosts as it did not pass its verify_file() method
[WARNING]: While constructing a mapping from /home/[email protected]/ansible/hosts, line 12, column 5, found a duplicate dict key (ansible_connection). Using last defined
value only.
Skipping empty key (control) in group (local)
Parsed /home/[email protected]/ansible/hosts inventory source with yaml plugin
Loading callback plugin minimal of type stdout, v2.0 from /home/[email protected]/.local/lib/python3.6/site-packages/ansible/plugins/callback/minimal.py
META: ran handlers
Using module file /home/[email protected]/.local/lib/python3.6/site-packages/ansible/modules/windows/win_ping.ps1
Pipelining is enabled.
<winhost.mydomain.local> ESTABLISH WINRM CONNECTION FOR USER: [email protected] on PORT 5986 TO winhost.mydomain.local
creating Kerberos CC at /tmp/tmpwetofduv
calling kinit with subprocess for principal [email protected]
kinit succeeded for principal [email protected]
<winhost.mydomain.local> WINRM CONNECT: transport=kerberos endpoint=https://winhost.mydomain.local:5986/wsman
<winhost.mydomain.local> WINRM CONNECTION ERROR: HTTPSConnectionPool(host='winhost.mydomain.local', port=5986): Max retries exceeded with url: /wsman (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:877)'),))
Traceback (most recent call last):
File "/home/[email protected]/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/[email protected]/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/home/[email protected]/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
conn.connect()
File "/home/[email protected]/.local/lib/python3.6/site-packages/urllib3/connection.py", line 394, in connect
ssl_context=context,
File "/home/[email protected]/.local/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib64/python3.6/ssl.py", line 365, in wrap_socket
_context=self, _session=session)
File "/usr/lib64/python3.6/ssl.py", line 773, in __init__
self.do_handshake()
File "/usr/lib64/python3.6/ssl.py", line 1033, in do_handshake
self._sslobj.do_handshake()
File "/usr/lib64/python3.6/ssl.py", line 645, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:877)
答え1
以前、Python 2.7 を実行したときに同じ問題が発生しました。Ansible を切り替えて Python 3 を使用すると、問題は解決しました。Python 2 は EOL でサポートが終了しているので、いずれにしてもそうするべきです。
Python 3 をインストールし (まだインストールされていない場合)、ansible_python_interpreter: /usr/bin/python3
Ansible 構成ファイルに次のような内容を追加します。