# connect to multiple vcenters and esxi hosts without host file

**URL:** <https://forum.ansible.com/t/connect-to-multiple-vcenters-and-esxi-hosts-without-host-file/37963>\
**Category:** Ansible Project\
**Created:** [May 4, 2023, 4:26pm UTC](https://forum.ansible.com/t/connect-to-multiple-vcenters-and-esxi-hosts-without-host-file/37963 "2023-05-04T16:26:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [May 4, 2023, 4:26pm UTC](https://forum.ansible.com/t/connect-to-multiple-vcenters-and-esxi-hosts-without-host-file/37963/1 "2023-05-04T16:26:29Z")

</div>

I got this pb but it is only working for single vcenter and I have to put the esxi hosts into a host file.

Is it possible to connect to multiple vcenters and lookup all the esxi hosts and connect to them instead of using host file?

vars.yml

vcenter\_hostname: [vcenter1.domain.com](http://vcenter1.domain.com)  
hostname: “{{ inventory\_hostname }}”

vcenter\_creds.yml has my credentials and I run the pb with --ask-vault-pass

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [May 4, 2023, 5:43pm UTC](https://forum.ansible.com/t/connect-to-multiple-vcenters-and-esxi-hosts-without-host-file/37963/2 "2023-05-04T17:43:55Z")

</div>

Here is something I tried

---

<div class="post-metadata">

**Author:** ![area51coder](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@area51coder](https://forum.ansible.com/u/area51coder)\
**Post date:** [May 5, 2023, 7:18am UTC](https://forum.ansible.com/t/connect-to-multiple-vcenters-and-esxi-hosts-without-host-file/37963/3 "2023-05-05T07:18:11Z")

</div>

please use vmware\_vm\_facts: module, it will collect all info connected to vmware, from there you can filter ESX names.

it will collect for all vcenter mentioned in your var2.yml file.

Ravi  
[yoursmartbook.blogspot.com](http://yoursmartbook.blogspot.com)
