Skip to content

Instantly share code, notes, and snippets.

@isweluiz
Last active November 14, 2022 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isweluiz/e9874dae63d66ae7e7e68703ebdc0123 to your computer and use it in GitHub Desktop.
Save isweluiz/e9874dae63d66ae7e7e68703ebdc0123 to your computer and use it in GitHub Desktop.

Ansible Inventory report with ansible-cmdb

Ansible-cmdb takes the output of Ansible's fact gathering and converts it into a static HTML overview page (and other things) containing system configuration information.

It supports multiple types of output (html, csv, sql, etc) and extending information gathered by Ansible with custom data. For each host it also shows the groups, host variables, custom variables and machine-local facts.

Installation

Ansible-cmdb can be installed using pip, the Python package manager. There are also stand-alone packages for various Linux distributions. Alternatively, you can use brew or plain old make install

For installation via Pip:

Install pip if you don't have it yet.

Install Ansible-cmdb with Pip:

sudo pip install ansible-cmdb

You can also upgrade Ansible-cmdb through Pip:

sudo pip install --upgrade ansible-cmdb

Generate report :: Collect fact

You can check the full documentation to get more details, I will just describe the essential here, that can be usefull to you don't waste time going on the documentation.

Before generate the report we should execute the ansible-cmd to collect the facts from our inventory and save the facts inside some folder:

$ mkdir output-fact

$ ansible -i /etc/ansible/inventory/hmg/web_servers all -m setup --tree output-fact/
  1. Create the output-fac
  2. Run ansible with setup module to get the facts and save it in the created folder

Generate report :: HTML report

$ ansible-cmdb -t html_fancy output-fact/ > web_servers-html.html

Generate report :: CSV report

$ ansible-cmdb -t csv output-fact/ > web_servers-csv.csv

HTML report

report-html

CSV report

csv-report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment