Loading...

Watch: Ansible troubleshooting - VMware certificate verify failed connecting to vCenter or ESXi

Learn how to resolve the "certificate verify failed" error in Ansible when connecting to VMware vCenter. Follow our step-by-step guide for a smooth fix.

Ansible troubleshooting - VMware certificate verify failed connecting to vCenter or ESXi

Today we're going to talk about Ansible troubleshooting, specifically about the "Unable to connect to vCenter or ESXi API [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (\_ssl.c:897)" message and enable Ansible For VMware.

This fatal error message happens when the Ansible controller is not able to connect to your VMware Infrastructure. The root cause might be a self-signed SSL certificate or a chain-of-trust not correctly installed in your Ansible Controller.

I'm Luca Berton and welcome to today's episode of Ansible Pilot.

Playbook

How to reproduce, troubleshoot, and fix the error "Unable to connect to vCenter or ESXi API[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (\_ssl.c:897)".

The best way of talking about Ansible troubleshooting is to jump in a live Playbook to show you practically the "Unknown error while connecting to vCenter or ESXi API [Errno -2] Name or service not known" and how to solve it!

In this Playbook, I'm going to reproduce the error and fix using the correct VMware hostname and verify the network configuration on a demo machine.

error code

  • vm_info.yml

``yaml

---

  • name: info vm Playbook

hosts: localhost

become: false

gather_facts: false

collections:

- community.vmware

pre_tasks:

- include_vars: vars.yml

tasks:

- name: get VM info

vmware_guest_info:

hostname: "{{ vcenter_hostname }}"

username: "{{ vcenter_username }}"

password: "{{ vcenter_password }}"

datacenter: "{{ vcenter_datacenter }}"

name: "{{ vm_name }}"

register: detailed_vm_info

- name: print VM info

ansible.builtin.debug:

var: detailed_vm_info

`

  • vars.yml

`yaml

---

vcenter_hostname: "vmware.example.com"

vcenter_datacenter: "vmwaredatacenter"

vcenter_username: "[email protected]"

vcenter_password: "MySecretPassword123"

vm_name: "myvm"

`

  • inventory

`ini

localhost

`

error execution

``bash

$ ansible-playbook vm_info.yml

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit

localhost does not match 'all'

PLAY [info vm Playbook] *

TASK [include_vars] *

ok: [localhost]

TASK [get VM info] *

Read the full tutorial: Ansible troubleshooting - VMware certificate verify failed connecting to vCenter or ESXi