I want to generate a report (probably using template) that groups my hosts based on facts about them.
Say I had the following servers in my /etc/ansible/hosts
(ansible_distribution
and ansible_distribution_version
facts as specified in brackets):
mercer (RedHat, 7.2)
grocer (RedHat, 6.2)
draper (Solaris, 10)
fishmonger (RedHat, 7.2)
goldsmith (Solaris, 11)
skinner (RedHat, 7.2)
What I want to do is end up with a file looking like:
**RedHat 6.2 Servers**
grocer
**RedHat 7.2 Servers**
mercer
fishmonger
skinner
**Solaris 10 Servers**
draper
**Solaris 11 Servers**
goldsmith
I don't know whether it would be better to try:
A) looping through play_hosts and pulling out the facts and writing into a new variable as ('fact1', 'fact2', 'hostname') and then looping over that new variable with groupby within my jinja2 template to generate the report.
B) Sorting them all in an ansible task, and then handing a pre-grouped array of arrays to template, and formatting that.
... and I can't work out how to do either.