Score:0

Ansible-inventory of Vcenter that contains more info than just the vm name

np flag

I'm fairly new to Ansible and VMware. I've created a playbook to gather inventory info about all the VM's in a Vcenter instance and it works fine, but I want the inventory output to include more than just the VM names. This is the playbook I have below.

---
plugin: community.vmware.vmware_vm_inventory
strict: False
hostname: 192.168.1.1
username: fake
password: name
validate_certs: False
with_tags: False
hostnames:
- config.name
properties:
- config.name
- config.guestId
- guest.ipAddress
- summary.runtime.powerState

This is a partial output of a long list:

 |--@centos64Guest:
  |  |--A-CentOS-xx.xx.xx.xx
  |  |--A.s-CentOS-xx.xx.xx.xx
  |  |--Alpha-DNS-xx.xx(CentOS)
  |  |--Alt-Services-xx.xx.xx.x
  |  |--Alt-Services-xx.xx.xx.xx
  |  |--Alt-Services-xx
  |  |--Alt-Services-xx.xxx
  |  |--Alt-Services-xx.xx

I only get the name of the VM. Is there a way to include more information about each VM like uptime/downtime? I know I can use a filter to just include powered off VM's...

- summary.runtime.powerState == "poweredOff"

But ultimately I need to know how long each VM has been powered off.

Thanks

Semicolon avatar
jo flag
Should be interesting - that information isn't tracked as far as I know even in vcenter. You would have to scrape the logs (if they go back that far) to find the poweroff event.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.