Use Ansible to discover/document an environment

653 views
Skip to first unread message

Jon Dison

unread,
Nov 3, 2015, 2:37:39 PM11/3/15
to Ansible Project
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.

Frank Ly

unread,
Nov 5, 2015, 6:20:30 PM11/5/15
to Ansible Project
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

Anil Dasmala

unread,
May 4, 2016, 7:56:01 AM5/4/16
to Ansible Project
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.

J Hawkesworth

unread,
May 4, 2016, 9:47:11 AM5/4/16
to Ansible Project
This project might be a help for you:


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

Jon Dison

unread,
May 4, 2016, 10:01:30 AM5/4/16
to ansible...@googlegroups.com
Yes,
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.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/4RWcMYB3zU8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/65001808-c200-4e12-8025-aaa259f8a00f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Anil Dasmala

unread,
May 5, 2016, 2:04:19 AM5/5/16
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages