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.
--- - hosts: localhost connection: local gather_facts: false vars: vcenters: - vc1 - vc2 - vc3 vcenter_username: "[email protected]" vcenter_password: "password" tasks: - name: Gather all registered virtual machines community.vmware.vmware_vm_info: hostname: '{{ item }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' validate_certs: False delegate_to: localhost register: myvm with_items: '{{ vcenters }}' - name: debug debug: msg: "{{ myvm }}" On Sunday, 23 January 2022 at 12:28:08 UTC [email protected] wrote: > 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: > [email protected] 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. > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c4a597c3-5393-4aa5-ba59-dcee1209fd64n%40googlegroups.com.
