# VmWare Inventory

**URL:** <https://forum.ansible.com/t/vmware-inventory/1194>\
**Category:** Get Help\
**Tags:** vmware, playbook, collections\
**Created:** [September 29, 2023, 1:18pm UTC](https://forum.ansible.com/t/vmware-inventory/1194 "2023-09-29T13:18:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![unixcommando](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/unixcommando/32/884_2.png) [@unixcommando](https://forum.ansible.com/u/unixcommando)\
**Post date:** [September 29, 2023, 1:18pm UTC](https://forum.ansible.com/t/vmware-inventory/1194/1 "2023-09-29T13:18:13Z")

</div>

Howdy,

I’m tasked with creating an ansible playbook that will generate an inventory our our VCenter. I need to be able to get the stats like available and used CPU, available and used memory, available and used disk as well as a count of active VMs in each of my clusters.

I’ve been able to create a playbook using the community.vmware.vmware\_cluster\_info module that gets CPU, Memory, and Disk information, and I see it can give me a list of the ESXI Hosts in the cluster, but where I’m running into a wall is getting a count of active vms in each cluster, the cluster information module doesn’t seem to provide that. I see that there are a number of vmware\_vm\_\* modules but all of those appear to get information about an individual vm. Since my need is a count of vms something that provides that would be the best solution, but I could do my own count if I can get a list of powered on vms in a cluster, or even a list of all vms in a cluster provided the list also gives me that state of the vm.

On a related topic, I see that community.vmware.vmware\_cluster\_info module allows you to define the exact properties you want it to return, what baffles me is where do I find a list of the property names? When I call the module under resource\_summary I can see that CPU info is provided by cpuCapacityMHz but that to call that in properties the examples shows summary.totalCpu as the property to call. I was able to get what resource\_summary calls memCapacityMB with summary.totalMemory following the example of totalCpu, but guessing at the other ones doesn’t result in the same mapping. So, how do I find out what the properties are called? The basic stats are available in the verbose output but that provides more than I’m looking for so if I can tailor my playbook for just the stats I want would be preferred.

Thanks in advance for any assistance.

Regards  
-Bob

---

<div class="post-metadata">

**Author:** ![IPvSean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ipvsean/32/1153_2.png) [@IPvSean](https://forum.ansible.com/u/IPvSean)\
**Post date:** [September 29, 2023, 2:41pm UTC](https://forum.ansible.com/t/vmware-inventory/1194/2 "2023-09-29T14:41:21Z")

</div>

> [@unixcommando](#):
>
> a wall is getting a count of active vms in each cluster, the cluster information module doesn’t seem to provide that. I see that there are a number of vmware\_vm\_\* modules but all of those appear to get in

you can register the output of any task including `community.vmware.vmware_cluster_info` and then debug the result out

for example:

```auto
- name: Gather info from datacenter about specific cluster with tags
  community.vmware.vmware_cluster_info:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    cluster_name: DC0_C0
    show_tag: true
  delegate_to: localhost
  register: cluster_info

- name: print it out to terminal
  ansible.builtin.debug:
    var: cluster_info

```

Also, consider using the dynamic inventory plugin for vmware [Using VMware dynamic inventory plugin — Ansible Documentation](https://docs.ansible.com/ansible/latest/collections/community/vmware/docsite/vmware_scenarios/vmware_inventory.html) to grab everything that is in there

---

<div class="post-metadata">

**Author:** ![maxamillion](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/maxamillion/32/98_2.png) [@maxamillion](https://forum.ansible.com/u/maxamillion)\
**Post date:** [September 29, 2023, 5:17pm UTC](https://forum.ansible.com/t/vmware-inventory/1194/3 "2023-09-29T17:17:17Z")

</div>

+1 for the VMWare dynamic inventory plugin!

---

<div class="post-metadata">

**Author:** ![unixcommando](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/unixcommando/32/884_2.png) [@unixcommando](https://forum.ansible.com/u/unixcommando)\
**Post date:** [September 29, 2023, 5:31pm UTC](https://forum.ansible.com/t/vmware-inventory/1194/4 "2023-09-29T17:31:01Z")

</div>

Hi,

Thanks for the response, I create a playbook based on your recommendation:

```auto
- hosts: localhost
  gather_facts: false
  collections:
   - community.vmare
  pre_tasks:
    - include_vars: vars.yml

  tasks:

    - name: collect a list of the datacenters
      community.vmware.vmware_cluster_info:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ generic_auth_username }}"
        password: "{{ ansible_awx_user_pw }}"
        validate_certs: no
        cluster_name: Perf
        show_tag: true
      delegate_to: localhost
      register: cluster_info

    - name: print it out to terminal
      ansible.builtin.debug:
        var: cluster_info

```

The above is similar to a running playbook that I have which gets inventory, my variables match what’s in my var file. When I run it I get the following error which looks like I have a broken module, is that correct and if so how do I fix?

The full traceback is:

```auto
Traceback (most recent call last):
  File "/tmp/ansible_community.vmware.vmware_cluster_info_payload_rs_xiu4o/ansible_community.vmware.vmware_cluster_info_payload.zip/ansible_collections/community/vmware/plugins/module_utils/vmware_rest_client.py", line 30, in <module>
    from com.vmware.vapi.std_client import DynamicID
ModuleNotFoundError: No module named 'com'
fatal: [localhost -> localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "cluster_name": "Perf",
            "datacenter": null,
            "hostname": "vcentererp.cf.cuny.edu",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "properties": null,
            "proxy_host": null,
            "proxy_port": null,
            "schema": "summary",
            "show_tag": true,
            "username": "awxadmin",
            "validate_certs": false
        }
    },
    "msg": "Failed to import the required Python library (vSphere Automation SDK) on ansible.cf.cuny.edu's Python /usr/bin/python3.6. See https://code.vmware.com/web/sdk/7.0/vsphere-automation-python for more info. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"

```

---

<div class="post-metadata">

**Author:** ![IPvSean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ipvsean/32/1153_2.png) [@IPvSean](https://forum.ansible.com/u/IPvSean)\
**Post date:** [September 29, 2023, 5:50pm UTC](https://forum.ansible.com/t/vmware-inventory/1194/5 "2023-09-29T17:50:58Z")

</div>

Hey unixcommando can you try reading this post from @Leo [Getting error while running a play from AWX 23.2.0 - #3 by Leo](http://forum.ansible.com/t/getting-error-while-running-a-play-from-awx-23-2-0/1192/3) because I am struggling to understand your post with the current formatting

---

<div class="post-metadata">

**Author:** ![unixcommando](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/unixcommando/32/884_2.png) [@unixcommando](https://forum.ansible.com/u/unixcommando)\
**Post date:** [October 2, 2023, 11:20am UTC](https://forum.ansible.com/t/vmware-inventory/1194/6 "2023-10-02T11:20:10Z")

</div>

Sorry about the formatting, I’m no more familiar with the editor on this forum than I am with Ansible, I copied and pasted what was on the screen and the editor changed it, put dots where hyphens were and changed all the indenting.

Regards  
-Bob

---

<div class="post-metadata">

**Author:** ![gwmngilfen](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gwmngilfen/32/6_2.png) [@gwmngilfen](https://forum.ansible.com/u/gwmngilfen)\
**Post date:** [October 2, 2023, 1:49pm UTC](https://forum.ansible.com/t/vmware-inventory/1194/7 "2023-10-02T13:49:47Z")

</div>

I fixed it for you @unixcommando - you need 3 backticks ``` not 3 dashes --- 🙂

---

<div class="post-metadata">

**Author:** ![IPvSean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ipvsean/32/1153_2.png) [@IPvSean](https://forum.ansible.com/u/IPvSean)\
**Post date:** [October 2, 2023, 1:59pm UTC](https://forum.ansible.com/t/vmware-inventory/1194/8 "2023-10-02T13:59:04Z")

</div>

you need to install the vSphere automaiton SDK so that the Ansible VMware modules will work: [vSphere Automation SDK for Python - VMware {code}](https://developer.vmware.com/web/sdk/8.0/vsphere-automation-python)

Can you try installing that and re-running?

---

<div class="post-metadata">

**Author:** ![unixcommando](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/unixcommando/32/884_2.png) [@unixcommando](https://forum.ansible.com/u/unixcommando)\
**Post date:** [October 2, 2023, 6:41pm UTC](https://forum.ansible.com/t/vmware-inventory/1194/9 "2023-10-02T18:41:44Z")

</div>

Cool thanks. I figured it had to be something like that, but it wasn’t obvious if I could edit the post.

Cheers  
-Bob

---

<div class="post-metadata">

**Author:** ![unixcommando](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/unixcommando/32/884_2.png) [@unixcommando](https://forum.ansible.com/u/unixcommando)\
**Post date:** [October 16, 2023, 11:14am UTC](https://forum.ansible.com/t/vmware-inventory/1194/10 "2023-10-16T11:14:06Z")

</div>

Unfortunatley I already have the plugin.
