Use Ansible to discover/document an environment

I’m wondering if anyone has any existing playbooks and/or scripts to go through an environment and document the findings.

Basically a way to transform the results from the setup module into a useful CSV would be a good start, but also adding on other facets like lists of patches to be applied, etc would be very useful.

I’ve made use of the setup module to create a directory of hosts files showing the results in YAML, but transforming that into a useful report would take some work and I figure someone out there may have already done it.

I’ve done something like this to create an inventory tracking spreadsheet. Haven’t had the chance yet to improve it or convert it into a proper playbook.

The setup module allows you to output facts to a tree structure with a JSON file for each host:

`
$ ansible all -i inventory -u admin -m setup --tree hosts_facts

facts/
├── host_A
├── host_B
├── host_C
├── host_D
└── host_Z

`

I used a command-line utility called jq to parse the JSON. See here: http://xmodulo.com/how-to-parse-json-string-via-command-line-on-linux.html

Then, just had to create a bash script to go through each file and extract the facts that I needed into a csv:

$ cat facts/host_A | jq .ansible_facts.ansible_distribution

Hi Jon,

I’m also trying to achieve the same, can you please share if you have made any progress with documenting facts to csv.

This project might be a help for you:

https://github.com/fboender/ansible-cmdb

It generates a static site but you can specify your own templates (jinja2 so already familiar) so you could use that to generate different output.

Hope this helps,

jon

Yes,
https://github.com/fboender/ansible-cmdb

Is what I settled upon.

Going forward we’re looking at a process to dump the facts into a database that has a web fronted, but for now the ansible-cmdb does fine.

Thank you so much for your replies. I tried ansible-cmdb earlier. -t txt_table or -t csv is giving limited columns.
I’m having difficulty in customizing fact columns that show up, should I edit /usr/lib/ansible-cmdb/ansiblecmdb/data/tpl/csv.tpl or txt_table.tpl for customizing?
Sorry not much in to jinja2 templating, but I"ll look at it. Any hints / suggestions will be helpful on how to customize.