# Use Ansible to discover/document an environment

**URL:** <https://forum.ansible.com/t/use-ansible-to-discover-document-an-environment/19686>\
**Category:** Ansible Project\
**Created:** [November 3, 2015, 7:37pm UTC](https://forum.ansible.com/t/use-ansible-to-discover-document-an-environment/19686 "2015-11-03T19:37:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Dison](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@Jon\_Dison](https://forum.ansible.com/u/Jon_Dison)\
**Post date:** [November 3, 2015, 7:37pm UTC](https://forum.ansible.com/t/use-ansible-to-discover-document-an-environment/19686/1 "2015-11-03T19:37:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CyberCyber](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@CyberCyber](https://forum.ansible.com/u/CyberCyber)\
**Post date:** [November 5, 2015, 11:20pm UTC](https://forum.ansible.com/t/use-ansible-to-discover-document-an-environment/19686/2 "2015-11-05T23:20:29Z")

</div>

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](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`

---

<div class="post-metadata">

**Author:** ![Anil\_Dasmala](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@Anil\_Dasmala](https://forum.ansible.com/u/Anil_Dasmala)\
**Post date:** [May 4, 2016, 11:56am UTC](https://forum.ansible.com/t/use-ansible-to-discover-document-an-environment/19686/3 "2016-05-04T11:56:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [May 4, 2016, 1:47pm UTC](https://forum.ansible.com/t/use-ansible-to-discover-document-an-environment/19686/4 "2016-05-04T13:47:11Z")

</div>

This project might be a help for you:

[https://github.com/fboender/ansible-cmdb](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

---

<div class="post-metadata">

**Author:** ![Jon\_Dison](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@Jon\_Dison](https://forum.ansible.com/u/Jon_Dison)\
**Post date:** [May 4, 2016, 2:01pm UTC](https://forum.ansible.com/t/use-ansible-to-discover-document-an-environment/19686/5 "2016-05-04T14:01:23Z")

</div>

Yes,  
[https://github.com/fboender/ansible-cmdb](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.

---

<div class="post-metadata">

**Author:** ![Anil\_Dasmala](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@Anil\_Dasmala](https://forum.ansible.com/u/Anil_Dasmala)\
**Post date:** [May 5, 2016, 6:04am UTC](https://forum.ansible.com/t/use-ansible-to-discover-document-an-environment/19686/6 "2016-05-05T06:04:18Z")

</div>

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.
