Electricmonk

Ferry Boender

Programmer, DevOpper, Open Source enthusiast.

Blog

Introducing ansible-cmdb: a host overview generator for ansible-managed hosts

Wednesday, August 12th, 2015

For those of you that are using Ansible to manage hosts, you may have noticed you can use the setup module to gather facts about the hosts in your inventory:

$ ansible -m setup --tree out/ all
$ ls out
centos.dev.local     eek.electricmonk.nl zoltar.electricmonk.nl
debian.dev.local     jib.electricmonk.nl
$ head out/debian.dev.local 
{
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.56.2"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::a00:27ff:fef9:98a7"
        ], 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "12/01/2006",
     ...etc... 

The setup module in combination with the --tree option produces a directory of JSON files containing facts about ansible-managed hosts such as hostnames, IP addresses, total available and free memory, and much more.

I wrote ansible-cmdb to take that output and generate an user-friendly host overview / CMDB (Configuration Management Database) HTML page. Usage is simple:

$ ansible -m setup --tree out/ all   # generate JSON output facts
$ ansible-cmdb out/ > cmdb.html      # generate host-overview page

Here's an example of what it produces.

And here's a screenshot:

ansible-cmdb-example

It can read your hosts inventory and gather variable values from it, which can be used in the templates that produce the output. You can also extend the gathered facts easily with your own facts by manually creating or generating additional output directories containing JSON files. This even allows you to manually define hosts which are not managed by Ansible.

Ansible-cmdb is template-driven, which means it's rather easy to modify the output. The output is generated using Mako templates

I've just released v1.2. Packages are available in source, Debian/Ubuntu and Redhat/Centos formats. 

For more information, see the Github page. I hope you like it!

The text of all posts on this blog, unless specificly mentioned otherwise, are licensed under this license.