list_inventory
Retrieve Ansible inventory hosts and groups using this tool to manage and organize infrastructure assets effectively. Ideal for system operators to streamline resource tracking and deployment tasks.
Instructions
List Ansible inventory hosts and groups
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inventory | No |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"inventory": {
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- The handler function that executes ansible-inventory --list command on the given inventory path, formats output as JSON, and handles errors.export async function listInventory(options: ListInventoryOptions): Promise<string> { const inventoryPath = validateInventoryPath(options.inventory); // Build command let command = 'ansible-inventory'; // Add inventory if specified if (inventoryPath) { command += ` -i ${inventoryPath}`; } command += ' --list'; try { // Execute command const { stdout, stderr } = await execAsync(command); try { // Try to parse as JSON for better formatting const inventory = JSON.parse(stdout); return JSON.stringify(inventory, null, 2); } catch { // Fall back to raw output if can't parse as JSON return stdout || 'No inventory data returned'; } } catch (error) { // Handle exec error const execError = error as { stderr?: string; message: string }; throw new AnsibleExecutionError( `Error listing inventory: ${execError.message}`, execError.stderr ); } }
- Zod schema for input validation: optional 'inventory' path string.export const ListInventorySchema = z.object({ inventory: z.string().optional(), }); export type ListInventoryOptions = z.infer<typeof ListInventorySchema>;
- src/sysoperator/index.ts:60-64 (registration)Tool registration in the toolDefinitions map, specifying description, schema, and handler.list_inventory: { description: 'List Ansible inventory hosts and groups', schema: ListInventorySchema, handler: inventory.listInventory, },