Skip to main content
Glama

list_inventory

Retrieve and display Ansible inventory hosts and groups using the specified inventory file for efficient server management.

Instructions

List Ansible inventory hosts and groups

Input Schema

NameRequiredDescriptionDefault
inventoryNo

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 runs 'ansible-inventory --list' on the specified inventory path, parses the JSON output if possible, and returns formatted inventory data or raw output. Handles validation and 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 list_inventory tool input: optional 'inventory' path string. Includes TypeScript type inference.
    export const ListInventorySchema = z.object({ inventory: z.string().optional(), }); export type ListInventoryOptions = z.infer<typeof ListInventorySchema>;
  • Tool registration in toolDefinitions map, specifying name 'list_inventory', description, schema, and handler reference.
    list_inventory: { description: 'List Ansible inventory hosts and groups', schema: ListInventorySchema, handler: inventory.listInventory, },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tarnover/mcp-ansible'

If you have feedback or need assistance with the MCP directory API, please join our Discord server