Loading...

Watch: Ansible troubleshooting - VMware Unknown error while connecting to vCenter or ESXi

Let’s troubleshoot together the Ansible fatal error “Unknown error while connecting to vCenter or ESXi API, [Errno -2] Name or service not known” to find the root cause, misspelled hostname in your Ansible Playbook, a connection problem connecting eventually using a secure VPN connection and successfully run our Ansible For VMware Playbook code.

Ansible troubleshooting - VMware Unknown error while connecting to vCenter or ESXi

Today we’re going to talk about Ansible troubleshooting, specifically about the “Unknown error while connecting to vCenter or ESXi API, [Errno -2] Name or service not known” 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 misspelled hostname in your Ansible Playbook, a connection problem connecting eventually using a secure VPN connection, or a configuration on the firewall on the target host.

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

## Playbook

How to reproduce, troubleshoot, and fix the error:

“Unknown error while connecting to vCenter or ESXi API [Errno -2] Name or service not known”

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.

Let’s suppose our infrastructure is accessible at the hostname “vmware.example.com”. Later in this Playbook, we’re going to see the misspelled “vm-ware.example.com”.

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 }}"

validate_certs: "{{ vcenter_validate_certs }}"

name: "{{ vm_name }}"

register: detailed_vm_info

- name: print VM info

ansible.builtin.debug:

var: detailed_vm_info

`

  • vars.yml

`yaml

---

vcenter_hostname: "vm-ware.example.com"

vcenter_datacenter: "vmwaredatacenter"

vcenter_validate_certs: false

vcenter_username: "[email protected]"

vcenter_password: "MySecretPassword123"

vm_name: "myvm"

vcenter_destination_folder: "myvm"

vm_template: "mytemplate"

`

  • 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] *

Read the full tutorial: Ansible troubleshooting - VMware Unknown error while connecting to vCenter or ESXi