Skip to main content

Overview

Ansible-cmdb uses the Mako templating engine to generate output in various formats. Templates control how host information is presented and can be customized or extended.

Specifying Templates

Use the -t or --template option to select a template:
ansible-cmdb -t html_fancy out/ > overview.html

Template References

Templates can be specified in two ways:
Use the built-in template name:
ansible-cmdb -t txt_table out/ > overview.txt

Available Templates

html_fancy (default)

A dynamic, modern HTML page with a searchable and sortable table overview of all hosts. Uses jQuery and DataTables for interactive functionality.
ansible-cmdb -t html_fancy out/ > overview.html
Features:
  • Interactive searchable/sortable table
  • Expandable host details
  • Responsive design
  • Optional local resource loading
Parameters:
local_js
boolean
default:"0"
Load JavaScript and CSS resources from local disk instead of CDN. Useful for offline viewing.
ansible-cmdb -p local_js=1 out/ > overview.html
collapsed
boolean
default:"0"
Collapse all host detail sections by default. Users can click to expand.
ansible-cmdb -p collapsed=1 out/ > overview.html
host_details
boolean
default:"1"
Control whether to render detailed host information sections.
ansible-cmdb -p host_details=0 out/ > overview.html
skip_empty
boolean
default:"0"
Skip hosts for which no facts were gathered (unreachable hosts, etc).
ansible-cmdb -p skip_empty=1 out/ > overview.html
Example with multiple parameters:
ansible-cmdb -t html_fancy -p local_js=1,collapsed=1 out/ > overview.html
Remember: Parameters must be separated by commas with no spaces.

html_fancy_split

Similar to html_fancy, but generates a cmdb/ directory with an index.html file and separate HTML files for each host’s details. Useful for large numbers of hosts where a single page might render slowly.
ansible-cmdb -t html_fancy_split -i hosts out/
Output structure:
cmdb/
├── index.html
├── host1.example.com.html
├── host2.example.com.html
└── ...
Parameters: Accepts the same parameters as html_fancy: local_js, collapsed, host_details, skip_empty.

txt_table

Generates a plain text table summary with minimal host information. Ideal for quick command-line viewing.
ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus facts/
Example output:
Name                    OS             IP             Mem  CPUs
----------------------  -------------  -------------  ---  -  
jib.electricmonk.nl     Linuxmint 17   192.168.0.3    16g  1  
app.uat.local           Debian 6.0.10  192.168.57.1   1g   1  
eek.electricmonk.nl     Ubuntu 14.04   192.168.0.10   3g   1  
Use the --columns option to control which columns are displayed.

json

Dumps all host information including groups, variables, and custom info in JSON format. Useful for programmatic access or integration with other tools.
ansible-cmdb -t json -i hosts out/ > cmdb.json
Use cases:
  • API integration
  • Custom processing scripts
  • Data analysis
  • Backup/archival

csv

Outputs host information in CSV (Comma-Separated Values) format. Compatible with spreadsheet applications and data analysis tools.
ansible-cmdb -t csv out/ > hosts.csv
Use cases:
  • Excel/spreadsheet import
  • Database imports
  • Reporting

markdown

Generates host documentation in Markdown format. Great for including in documentation systems or version control.
ansible-cmdb -t markdown out/ > hosts.md

sql

Generates SQL statements that can be loaded into SQLite or MySQL databases.
ansible-cmdb -t sql -i hosts out/ > cmdb.sql
Loading into MySQL:
echo "CREATE DATABASE ansiblecmdb" | mysql
mysql ansiblecmdb < cmdb.sql

Template Parameters

Parameters are passed to templates using the -p or --params option:
ansible-cmdb -p param1=value1,param2=value2 out/ > output.html
Parameter syntax:
  • Use commas to separate parameters (no spaces!)
  • Format: key=value
  • Boolean values: 0 or 1
  • Example: local_js=1,collapsed=1
  • Wrong: local_js=1, collapsed=1 ✗ (space after comma)

Custom Templates

You can create custom templates to build completely different output or enhance existing templates. Ansible-cmdb uses the Mako templating engine.

Creating a Custom Template

  1. Copy an existing template:
mkdir ~/mytemplate
cp ~/ansible-cmdb/src/ansiblecmdb/data/tpl/html_fancy.tpl ~/mytemplate/
cp ~/ansible-cmdb/src/ansiblecmdb/data/tpl/html_fancy_defs.html ~/mytemplate/
  1. Modify the template files according to your needs.
  2. Render with your custom template:
You must be in the same directory as the custom template when rendering.
cd ~/mytemplate
ansible-cmdb -t ./html_fancy.tpl -i ~/ansible/hosts ~/ansible/out/ > cmdb.html

Template Resources

Templates have access to:
  • host - Host fact data
  • jsonxs() - Function for safe JSON navigation
  • Various helper functions defined in template files

Example: Adding Custom Columns

To add a BIOS version column to html_fancy:
  1. Edit html_fancy_defs.html and add to the cols array:
cols = [
  # ... existing columns ...
  {"title": "BIOS version", "id": "bios_version", "func": col_bios_version, "sType": "string", "visible": True},
]
  1. Add the column function:
<%def name="col_bios_version(host, **kwargs)">
  ${jsonxs(host, 'ansible_facts.ansible_bios_version', default='')}
</%def>
For simpler column customization, use the --cust-cols option instead of modifying templates directly.

Template Compatibility

Featurehtml_fancyhtml_fancy_splittxt_tablejsoncsvmarkdownsql
Columns---
Custom columns-----
Parameters-----
Exclude columns---

Best Practices

  • Use html_fancy for interactive web-based CMDBs
  • Use html_fancy_split for large infrastructures (100+ hosts)
  • Use txt_table for quick command-line checks
  • Use json for automation and integration
  • Use sql for database-driven reporting systems

Build docs developers (and LLMs) love