list_inventory
View Ansible inventory hosts and groups to manage infrastructure configurations and deployments.
Instructions
List Ansible inventory hosts and groups
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inventory | No |
Implementation Reference
- The handler function that runs 'ansible-inventory --list' to list hosts and groups, formats as pretty JSON, with error handling.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 of the list_inventory tool, accepting an optional inventory path.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 object, specifying name, description, schema, and handler reference.list_inventory: { description: 'List Ansible inventory hosts and groups', schema: ListInventorySchema, handler: inventory.listInventory, },