Overview
Ansible-cmdb can read your Ansible inventory files and extract valuable information to enhance the generated CMDB:- Host group memberships
- Host variables (custom key/value pairs)
- Group variables from
host_vars/andgroup_vars/directories
Basic Usage
Use the-i or --inventory option to specify your inventory:
Inventory Types
Ansible-cmdb supports all Ansible inventory types:- Single File
- Directory
- Dynamic Inventory
- Multiple Inventories
Point to a single hosts file:
Host and Group Variables
When you point ansible-cmdb to your inventory with-i, it automatically includes variables from:
host_vars/directory (if found in the same location)group_vars/directory (if found in the same location)- Inline host variables in the inventory file
Directory Structure
host_vars/ and group_vars/ data.
Special Variables
Thehtml_fancy and html_fancy_split templates recognize four special host variables:
List of Ansible groups the host belongs to. Displayed in the host overview table.
Environment type:
dev, test, acc, or prod. Displayed in the host overview table.Free-form comment about the host. Displayed in the host overview table.
External unique identifier for the host (e.g., asset ID, ticket number). Displayed in the host overview table.
Example Inventory
Here’s a complete example showing all features:Resulting Host Information
Based on the above inventory: acc.megacorp.com:- Groups:
cust.megacorp,os.redhat - DTAP:
acc - Comment: “24/7 support”
- Groups:
cust.megacorp,os.redhat - DTAP:
prod - Comment: “Hosting by Foo”
- External ID: “SRV_10029”
Custom Variables
All host variables are available in templates under thehostvars section. In the html_fancy template, custom variables appear under the “Custom variables” heading.
Example with host_vars
hosts file:Variable Visibility
Whether variables are included in the output depends on the template used:
html_fancy/html_fancy_split: Shows variables under “Custom variables”json: Includes all variables in the outputtxt_table: Limited variable displaycsv: Selected variables only
Use Cases
- Environment Tracking
- Asset Management
- Documentation
- Grouping
Use
dtap to identify which environment each host belongs to:Combining with Limiting
Inventory scanning is required when using the--limit option to filter hosts:
Best Practices
Troubleshooting
host_vars and group_vars not loaded
Ensure the directories exist in the same location as your inventory file:Variables not appearing in output
Check that you’re using a template that displays variables:html_fancy- Shows under “Custom variables”json- Includes all variablestxt_table- Limited support