Sorry if I misunderstood what you’re trying to achieve, but if you need to see OS with the number of associated hosts, but based on reported facts, you can try this snippet out:
This is not so optimized due to lack of additional macros, but what it does is: load hosts, checks if its OS name and version are in the its reported facts, adds OS name and version to the os_counter, updates count and then prints something like:
Thank you @ofedoren! I exactly needed what you submitted in sense of the logic! I modified it a bit because CentOS is using some other facts then Ubuntu, but now I finally get the expected data.