# create single vmware dynamic inventory from multiple vcenters

**URL:** <https://forum.ansible.com/t/create-single-vmware-dynamic-inventory-from-multiple-vcenters/36242>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [January 23, 2022, 12:28pm UTC](https://forum.ansible.com/t/create-single-vmware-dynamic-inventory-from-multiple-vcenters/36242 "2022-01-23T12:28:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amjad\_Saleem1](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Amjad\_Saleem1](https://forum.ansible.com/u/Amjad_Saleem1)\
**Post date:** [January 23, 2022, 12:28pm UTC](https://forum.ansible.com/t/create-single-vmware-dynamic-inventory-from-multiple-vcenters/36242/1 "2022-01-23T12:28:08Z")

</div>

I am trying to collect all vms in four different vcenters to create inventory and further act on the that inventory. Using vmware\_vm\_inventory, I can target one vcenter and hostname does not support a list:

plugin: vmware\_vm\_inventory strict: False hostname: 10.65.223.31 username: administrator@vsphere.local password: XXXXXYYZZ validate\_certs: False with\_tags: True

I can make hostname as variable and provide it at runtime but then I will have run the playbook four times.

Is there a way to collect vms from all four vcenters and then run tasks on them?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Rodrigues](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@Rodrigues](https://forum.ansible.com/u/Rodrigues)\
**Post date:** [January 23, 2022, 5:25pm UTC](https://forum.ansible.com/t/create-single-vmware-dynamic-inventory-from-multiple-vcenters/36242/2 "2022-01-23T17:25:40Z")

</div>

Not sure exactly what details you need from VMs, but defining vcenters as vars or part of your inventory will get you a list of vms using vmware\_vm\_info. Just update the vars section and add as many VCs as you’d like. You will end up with a list of vcenters and whitin the VM details.

---

<div class="post-metadata">

**Author:** ![Amjad\_Saleem1](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@Amjad\_Saleem1](https://forum.ansible.com/u/Amjad_Saleem1)\
**Post date:** [January 23, 2022, 5:46pm UTC](https://forum.ansible.com/t/create-single-vmware-dynamic-inventory-from-multiple-vcenters/36242/3 "2022-01-23T17:46:43Z")

</div>

Thanks Rodrigues. The ended up using separate inventory file for each vcenter and than specifying them with multiple -i flags like so:  
ansible-inventory -i inventory\_file1.yml -i inventory\_file2.yml -i inventory\_file3.yml  
to get all the vms in all the vcenters.
