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:
Template References
Templates can be specified in two ways:- By Name
- By Path
Use the built-in template name:
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.- Interactive searchable/sortable table
- Expandable host details
- Responsive design
- Optional local resource loading
Load JavaScript and CSS resources from local disk instead of CDN. Useful for offline viewing.
Collapse all host detail sections by default. Users can click to expand.
Control whether to render detailed host information sections.
Skip hosts for which no facts were gathered (unreachable hosts, etc).
Remember: Parameters must be separated by commas with no spaces.
html_fancy_split
Similar tohtml_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.
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.json
Dumps all host information including groups, variables, and custom info in JSON format. Useful for programmatic access or integration with other tools.- 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.- Excel/spreadsheet import
- Database imports
- Reporting
markdown
Generates host documentation in Markdown format. Great for including in documentation systems or version control.sql
Generates SQL statements that can be loaded into SQLite or MySQL databases.Template Parameters
Parameters are passed to templates using the-p or --params option:
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
- Copy an existing template:
- Modify the template files according to your needs.
- Render with your custom template:
You must be in the same directory as the custom template when rendering.
Template Resources
Templates have access to:host- Host fact datajsonxs()- Function for safe JSON navigation- Various helper functions defined in template files
Example: Adding Custom Columns
To add a BIOS version column tohtml_fancy:
- Edit
html_fancy_defs.htmland add to thecolsarray:
- Add the column function:
Template Compatibility
| Feature | html_fancy | html_fancy_split | txt_table | json | csv | markdown | sql |
|---|---|---|---|---|---|---|---|
| Columns | ✓ | ✓ | ✓ | - | ✓ | - | - |
| Custom columns | ✓ | ✓ | - | - | - | - | - |
| Parameters | ✓ | ✓ | - | - | - | - | - |
| Exclude columns | ✓ | ✓ | ✓ | - | ✓ | - | - |