So you’ve been asked to gather a report of several metrics of some servers you manage. It needs to be readable, so tabular output would be best. What can we do with ansible?
Well, we can leverage facts to get the data we desire, and then output them locally to a template csv.
Create a local jinja2 csv template file with the fields desired. In my case, we’ll be gathering mostly hardware specific information:
Now, we’ll form our playbook as such:
Note: This example will require you to have the same credentials locally as well as remotely. If your user account locally differs from your remote account used for fact gathering, you’ll need to play around with your
ansible.cfg and likely
ansible-vault along with inventory variables to manage separate passwords.
Here’s an example of the resulting local
hostname,system_vendor,product_name,platform,memory(mb),number_of_cpus server1,QEMU,Standard PC (Q35 + ICH9, 2009),CentOS 9,3719,2 server2,QEMU,Standard PC (Q35 + ICH9, 2009),CentOS 9,7125,4