Skip to main content
ansible-cmdb uses templates to generate different output formats. Templates are stored as .tpl files and Python scripts in the src/ansiblecmdb/data/tpl/ directory.

Available Templates

The following templates are available in ansible-cmdb:

csv.tpl

CSV spreadsheet output format

html_fancy.tpl

Main fancy HTML template with DataTables integration

html_fancy_split.py

Split HTML generator (Python script)

json.tpl

JSON export template

markdown.tpl

Markdown output template

markdown_split.py

Split Markdown generator (Python script)

sql.tpl

SQL database export template

txt_table.tpl

Plain text table template

Template Files

The template system consists of several types of files:

Template Files (.tpl)

Mako template files that generate output:
  • csv.tpl - CSV output
  • html_fancy.tpl - Main HTML template
  • json.tpl - JSON output
  • markdown.tpl - Markdown output
  • sql.tpl - SQL output
  • txt_table.tpl - Text table output

Python Scripts (.py)

Python generators for complex multi-file output:
  • html_fancy_split.py - Generates split HTML output
  • markdown_split.py - Generates split Markdown output

Split Template Components

Templates used by split generators:
  • html_fancy_split_overview.tpl - Overview page for HTML split
  • html_fancy_split_detail.tpl - Detail pages for HTML split
  • markdown_split_overview.tpl - Overview page for Markdown split
  • markdown_split_detail.tpl - Detail pages for Markdown split

Shared Definitions

  • html_fancy_defs.html - Column definitions and helper functions used by HTML templates

HTML Templates

html_fancy.tpl

Type: Single-file template
Output: One HTML file with all hosts
The main fancy HTML template that creates an interactive, searchable, sortable table of hosts using jQuery and DataTables.

Parameters

ParameterTypeDefaultDescription
local_js0|10Load JavaScript resources from local disk instead of CDN
collapsed0|10Collapse host information by default
host_details0|11Render host details section
skip_empty0|10Skip hosts with no gathered facts (unreachable hosts)

Example

ansible-cmdb -t html_fancy -p local_js=1 -p collapsed=1 -i hosts out/ > overview.html

html_fancy_split.py

Type: Multi-file generator
Output: Directory with index.html and separate host detail files
Generates a split HTML output with a main overview page and individual HTML files for each host. Better performance for large inventories.

Parameters

Accepts the same parameters as html_fancy.tpl:
ParameterTypeDefaultDescription
local_js0|10Load JavaScript resources from local disk
collapsed0|10Collapse host information by default
host_details0|11Render host details section
skip_empty0|10Skip hosts with no gathered facts

Example

ansible-cmdb -t html_fancy_split -i hosts out/

Output Structure

cmdb/
├── index.html              # Overview page with host table
├── hostname1.html          # Detail page for hostname1
├── hostname2.html          # Detail page for hostname2
└── ...

Text Templates

txt_table.tpl

Type: Single-file template
Output: Plain text table
Generates a simple text table suitable for terminal display.

Column Support

Supports the --columns flag to customize displayed columns. See Column Reference.

Example

ansible-cmdb -t txt_table --columns name,os,ip,mem,cpus facts/

Data Export Templates

json.tpl

Type: Single-file template
Output: JSON file
Exports all host information in JSON format including facts, groups, variables, and custom data.

Example

ansible-cmdb -t json -i hosts out/ > cmdb.json

csv.tpl

Type: Single-file template
Output: CSV file
Exports host information in CSV format for spreadsheet applications.

Example

ansible-cmdb -t csv -i hosts out/ > hosts.csv

sql.tpl

Type: Single-file template
Output: SQL file
Generates SQL statements to create and populate database tables with host information.

Parameters

No template-specific parameters.

Example

ansible-cmdb -t sql -i hosts out/ > cmdb.sql

# Load into MySQL
echo "CREATE DATABASE ansiblecmdb" | mysql
mysql ansiblecmdb < cmdb.sql

# Or SQLite
sqlite3 cmdb.db < cmdb.sql

Markdown Templates

markdown.tpl

Type: Single-file template
Output: Markdown file
Generates host documentation in Markdown format.

Example

ansible-cmdb -t markdown -i hosts out/ > hosts.md

markdown_split.py

Type: Multi-file generator
Output: Directory with index.md and separate host detail files
Generates split Markdown output similar to html_fancy_split.

Example

ansible-cmdb -t markdown_split -i hosts out/

Output Structure

out/
├── index.md                # Overview page
├── hostname1.md            # Detail page for hostname1
├── hostname2.md            # Detail page for hostname2
└── ...

Template Definitions

html_fancy_defs.html

This file contains shared definitions used by HTML templates:
  • Column definitions: Defines all available columns for the host overview table
  • Helper functions: Functions for rendering data structures (lists, dicts)
  • HTML fragments: Reusable HTML components (header, footer, etc.)
  • JavaScript fragments: DataTables initialization and event handlers
  • Column functions: Functions to extract and format data for each column
See Column Reference for details on available columns.

Using Template Parameters

Template parameters are passed using the -p or --params flag:
ansible-cmdb -t template_name -p param1=value1 -p param2=value2 ...

Multiple Parameters

ansible-cmdb -t html_fancy -p local_js=1 -p collapsed=1 -p skip_empty=1 -i hosts out/ > overview.html

Custom Templates

You can create custom templates by:
  1. Creating a new .tpl file in the template directory
  2. Using Mako template syntax
  3. Accessing host data via the hosts dictionary
  4. Using helper functions from html_fancy_defs.html (for HTML templates)
Refer to existing templates as examples for custom template development.

Build docs developers (and LLMs) love