简体   繁体   中英

Ansible VMware - Any module or method can search a vm folder and return its VM guest list?

I am working on Ansible automation and need to get the VM list from searching a specific VM folder in vCenter.

As I know there is a module "vcenter_folder.py", it can create or delete a vcenter folder but cannot return information/fact.

Does anyone know how can I get the vm list using Ansible? thank you so much.

here is how to return all vms in a folder :

---
- hosts: localhost
  connection: local
  vars:
  vars_files:
            - vars.yml
  tasks:
   - name: returning vm list on a folder
     vmware_vm_info:
        validate_certs: no
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_user  }}"
        password: "{{ vcenter_pass }}"
        folder: "datacenter/vm/foldername"
     register: vms
   - debug:
         msg: "{{ vms | json_query('virtual_machines[*].guest_name') }}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM