.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 outputhtml_fancy.tpl- Main HTML templatejson.tpl- JSON outputmarkdown.tpl- Markdown outputsql.tpl- SQL outputtxt_table.tpl- Text table output
Python Scripts (.py)
Python generators for complex multi-file output:html_fancy_split.py- Generates split HTML outputmarkdown_split.py- Generates split Markdown output
Split Template Components
Templates used by split generators:html_fancy_split_overview.tpl- Overview page for HTML splithtml_fancy_split_detail.tpl- Detail pages for HTML splitmarkdown_split_overview.tpl- Overview page for Markdown splitmarkdown_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 templateOutput: 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
| Parameter | Type | Default | Description |
|---|---|---|---|
local_js | 0|1 | 0 | Load JavaScript resources from local disk instead of CDN |
collapsed | 0|1 | 0 | Collapse host information by default |
host_details | 0|1 | 1 | Render host details section |
skip_empty | 0|1 | 0 | Skip hosts with no gathered facts (unreachable hosts) |
Example
html_fancy_split.py
Type: Multi-file generatorOutput: 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 ashtml_fancy.tpl:
| Parameter | Type | Default | Description |
|---|---|---|---|
local_js | 0|1 | 0 | Load JavaScript resources from local disk |
collapsed | 0|1 | 0 | Collapse host information by default |
host_details | 0|1 | 1 | Render host details section |
skip_empty | 0|1 | 0 | Skip hosts with no gathered facts |
Example
Output Structure
Text Templates
txt_table.tpl
Type: Single-file templateOutput: 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
Data Export Templates
json.tpl
Type: Single-file templateOutput: JSON file Exports all host information in JSON format including facts, groups, variables, and custom data.
Example
csv.tpl
Type: Single-file templateOutput: CSV file Exports host information in CSV format for spreadsheet applications.
Example
sql.tpl
Type: Single-file templateOutput: SQL file Generates SQL statements to create and populate database tables with host information.
Parameters
No template-specific parameters.Example
Markdown Templates
markdown.tpl
Type: Single-file templateOutput: Markdown file Generates host documentation in Markdown format.
Example
markdown_split.py
Type: Multi-file generatorOutput: Directory with index.md and separate host detail files Generates split Markdown output similar to html_fancy_split.
Example
Output Structure
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
Using Template Parameters
Template parameters are passed using the-p or --params flag:
Multiple Parameters
Custom Templates
You can create custom templates by:- Creating a new
.tplfile in the template directory - Using Mako template syntax
- Accessing host data via the
hostsdictionary - Using helper functions from
html_fancy_defs.html(for HTML templates)