This tool is what you need, just run pve-hosts >> /etc/hosts
to get every PVE cluster node ip address on vmbr0(or any other, specify with -iface flag) interface in /etc/hosts
pve-hosts [-iface <ifname>]
This one (if it executed on cluster node) prints to stdout list of hosts with it ip addresses, if no iface flag specified, ip address of vmbr0 interface will be printed. If node have no ip on given interface, it will not be included in list
Works great with PVE 5.3 and 5.4, i guess it will work on other 5.x installations. Currently i have no PVE v6 cluster to test compatibility, so it may work on v6, but im not sure
Also you can generate list in ansible hosts file format by specifying -format ansible
flag
If node have multiple IP addressess on given interface, only first one will be included, for others specify interface with index (ex. vmbr0:1)
You need all your cluster nodes to be online, to generate host list
Also if you have issues with your /etc/ssh/ssh_known_hosts file, execution will fail
Execution time depends on number of nodes in cluster. This tool is using pvesh to access proxmox API, every request takes approx. 2s to finish on idling node, number of requests needed to build the list is . For now requests executing one by one, but maybe later i will make info gathering asynchronous to reduce execution time, or you can do it yourself via PR or forking :)
Have a nice day!