AnsibleでVMwareの仮想環境操作時に、Unable to connect to vCenter or ESXi API at IP on TCP/443: [SSL: CERTIFICATE_VERIFY_FAILED] というメッセージが出て、実行が正常に完了しない場合の情報になります。
以下は情報元です。
以下は質問の抜粋です。
ホストに対してプレイブックを実行していると、以下のようなエラーが発生します。"Unable to connect to vCenter or ESXi API at 192.11.11.111 on TCP/443: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)"
vcenter 6.5を使用しています。ansible controllerがvsphere vcenterと通信するためのプレイブックを作成しました。信頼されたルートのSSL証明書をvSphereのホームページからエクスポートしました。ansible controllerにコピーして、インストールしました。
sudo mv 9dab0099.0.crt 9dab0099.r0.crl 11ec582d.0.crt /etc/pki/ca-trust/source/anchors
sudo update-ca-trust force -enable
sudo update-ca-trust extract
・443でホストにtelnetできること
・ホストへの継続的なpingが可能
・validate_certsをnoに変更してみました。
・有効な暗号を yes に変更してみました。
・validate_certs を false に変更してみました。
私のプレイブック
- name: Add an additional cpu to virtual machine server
hosts: '{{ target }}'
tasks:
- name: Login into vCenter and get cookies
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: "{{ vm_folder }}"
cluster: "{{ vcenter_cluster }}"
datacenter: "{{ vcenter_datacenter }}"
name: "{{ vm_name }}"
- name:
uri:
url: https://{{ vcenter_hostname }} #/rest/com/vmware/cis/session
force_basic_auth: yes
validate_certs: no
method: POST
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: "{{ vm_folder }}"
cluster: "{{ vcenter_cluster }}"
datacenter: "{{ vcenter_datacenter }}"
name: "{{ vm_name }}"
#register: login
- name: Stop virtual machine
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
folder: "{{ vm_folder }}"
cluster: "{{ vcenter_cluster }}"
datacenter: "{{ vcenter_datacenter }}"
name: "{{ vm_name }}"
state: "poweredoff"- name: reconfigure CPU and RAM of VM
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster: "{{ vcenter_cluster }}"
datacenter: "{{ vcenter_datacenter }}"
name: "{{ vm_name }}"
state: "present"
validate_certs: "false"
folder: "{{ vm_folder }}"
hardware:
memory_gb: "{{ memory }}"
num_cpus: "{{ cpu }}"
scsi: "lsilogic"
ESXiのfwルールは開いています。
python 2.7.5とpython 3.6でエラーを再現しました。pyvmomiの最新版をインストールしています。
誰かここから正しい方向に導いてくれませんか?
以下は回答内容です。
証明書に何らかの問題があるようです。確認してください。
ちなみに、validate_certs を false は新しいバージョンでは対応していないようです。
Installing vCenter SSL certificates for Ansible
From any web browser, go to the base URL of the vCenter Server without port number like https://vcenter-domain.example.comClick the “Download trusted root CA certificates” link at the bottom of the grey box on the right and download the file.
Change the extension of the file to .zip. The file is a ZIP file of all root certificates and all CRLs.
Extract the contents of the zip file. The extracted directory contains a .certs directory that contains two types of files. Files with a number as the extension (.0, .1, and so on) are root certificates.
Install the certificate files are trusted certificates by the process that is appropriate for your operating system.
証明書に関するエラーなので、このあたりの対応が必要そうです。