Thanks for your answer.
My goal is to have a list like this :
- ESX 1 - RAM 50% - CPU 40%
- ESX 2 - RAM 50% - CPU 40%
- ESX 3 - RAM 50% - CPU 40%
....
Data is collected with "community.vmware.vmware_host_facts". Currently, here is my playbook :
- name: "ESX information"
community.vmware.vmware_host_facts:
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
validate_certs: no
esxi_hostname: "{{ item.name }}"
schema: vsphere
properties:
- hardware.memorySize
- hardware.cpuInfo.numCpuCores
- hardware.cpuInfo.hz
- summary.quickStats.overallMemoryUsage
- summary.quickStats.overallCpuUsage
- config.fileSystemVolume.mountInfo
with_items: "{{ liste_ESX | json_query('*.value') }}"
register: esxi_infos
- set_fact:
esx_conf: "{{ item.item.name }} - RAM : {{ (( item.ansible_facts.summary.quickStats.overallMemoryUsage / ( item.ansible_facts.hardware.memorySize / (1024*1024) ) ) * 100 ) | int }}% - CPU : {{ (( item.ansible_facts.summary.quickStats.overallCpuUsage / ( item.ansible_facts.hardware.cpuInfo.numCpuCores * ( item.ansible_facts.hardware.cpuInfo.hz / 1000000 ) ) ) * 100) | int }}%"
with_items: "{{ esxi_infos.results }}"
register: all_esx_conf
- set_fact:
esx_conf: "{{ item.ansible_facts.esx_conf }}"
with_items: "{{ all_esx_conf.results }}"
register: all_esx_conf
- debug:
msg: "{{ all_esx_conf.results | map(attribute='ansible_facts.esx_conf') | list }}"
The result is :
TASK [debug] ***************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": [
"ESX 1 - RAM : 74% - CPU : 11%",
"ESX 2 - RAM : 70% - CPU : 11%",
"ESX 3 - RAM : 65% - CPU : 13%",
...
]
}
After that, I have a pause :
- pause:
prompt: "ESX chosen ?"
register: prompt
So, with a counter for each "ITEM", the user will type 1,2,3...to choose the ESX.
What do you think?
Thanks !