I'm trying to write an ansible code that would fetch VMs from a particular datacenter using vmware modules retaining their folder structure. Imagine going through the VMs and Templates view in Vcenter. First we fix a data center and the first folder inside it. We collect all the VMs' detail pertaining to the data center and folder. We then move on to the next folder in the data center, similarly collecting its VM details as well. We do the same till all the VMs of the data center are covered. After this process, I would preferably need the data in json format with the data center and its corresponding folders inside it, with the details of VMs inside each folder respectively.
I've not found a way to organize the VMs in a data center directly this way by using a vmware ansible module. Any suggestion on getting the VMs of a data center with their folder structure would be really helpful.
I've so far tried to peruse through ansible's available Vmware modules but have not had any luck finding a module that searches by the data center and its folders for VMs. So, as of now the best bet for me was to find all VM details in a VCenter (using vmware_vm_facts module) and take each VM and find its folder location in Vcenter (using vmware_guest_find module) iteratively. If I go on with this method, I still have to find a way to organize the resultant data structure into - folder1 -> VMs of folder1, folder2 -> VMs of folder 2,... format.