Skip to main content
Glama

aws_dynamic_inventory

Generate dynamic Ansible inventory from AWS resources by region, applying filters, hostname mapping, and grouping for infrastructure automation.

Instructions

Create AWS dynamic inventory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYes
filtersNo
hostnamesNo
keyed_groupsNo
composeNo

Implementation Reference

  • Handler function that generates AWS EC2 dynamic inventory YAML using the aws_ec2 plugin, saves it to a temp file, runs 'ansible-inventory --list' to display structure, and tests with a ping playbook on discovered hosts.
    export async function dynamicInventoryOperations(args: DynamicInventoryOptions): Promise<string> {
      await verifyAwsCredentials();
    
      const { region, filters, hostnames, keyed_groups, compose } = args;
    
      let inventoryContent = `---
    plugin: amazon.aws.aws_ec2
    regions:
      - ${region}`;
    
      if (filters) {
        inventoryContent += `
    filters:
    ${formatYamlParams(filters, 2)}`; // Indent level 2 for filters
      }
    
      if (hostnames && hostnames.length > 0) {
        inventoryContent += `
    hostnames:
    ${hostnames.map(h => `  - ${JSON.stringify(h)}`).join('\n')}`;
      }
    
      if (keyed_groups && keyed_groups.length > 0) {
        inventoryContent += `
    keyed_groups:
    ${keyed_groups.map(group => `  - prefix: ${group.prefix}\n    key: ${group.key}\n    separator: ${group.separator ?? ''}`).join('\n')}`;
      }
      
      if (compose) {
        inventoryContent += `
    compose:
    ${formatYamlParams(compose, 2)}`; // Indent level 2 for compose
      }
    
      // This operation doesn't run a playbook, it *generates* an inventory file
      // and then tests it. We'll adapt the helper pattern slightly.
      let tempDir: string | undefined;
      try {
        tempDir = await createTempDirectory('ansible-aws-dyninv');
        const inventoryPath = await writeTempFile(tempDir, 'inventory.aws_ec2.yml', inventoryContent);
    
        // Create a simple test playbook
        const testPlaybookContent = `---
    - name: Test AWS Dynamic Inventory
      hosts: all # Target hosts defined by the dynamic inventory
      gather_facts: no
      tasks:
        - name: Ping hosts found by dynamic inventory
          ansible.builtin.ping:`;
    
        const testPlaybookPath = await writeTempFile(tempDir, 'test_playbook.yml', testPlaybookContent);
    
        // Execute ansible-inventory --list first to show the structure
        const listCommand = `ansible-inventory -i ${inventoryPath} --list`;
        console.error(`Executing: ${listCommand}`);
        const listResult = await execAsync(listCommand);
    
        // Execute the test playbook using the dynamic inventory
        const runCommand = `ansible-playbook -i ${inventoryPath} ${testPlaybookPath}`;
        console.error(`Executing: ${runCommand}`);
        const runResult = await execAsync(runCommand);
    
        return `Dynamic Inventory (${inventoryPath}) Content:\n${inventoryContent}\n\nInventory List Output:\n${listResult.stdout}\n\nPlaybook Test Output:\n${runResult.stdout}`;
    
      } catch (error: any) {
        const errorMessage = error.stderr || error.message || 'Unknown error';
        throw new AnsibleExecutionError(`Failed dynamic inventory operation: ${errorMessage}`, error.stderr);
      } finally {
        if (tempDir) {
          await cleanupTempDirectory(tempDir);
        }
      }
    }
  • Zod schema defining the input parameters for the aws_dynamic_inventory tool: required AWS region, optional filters, hostnames, keyed_groups, and compose options.
    export const DynamicInventorySchema = z.object({
      region: z.string().min(1, 'AWS region is required'),
      filters: z.record(z.any()).optional(),
      // Changed hostnames to allow array of strings based on aws.ts usage
      hostnames: z.array(z.string()).optional(), 
      // Changed keyed_groups to match structure used in aws.ts
      keyed_groups: z.array(z.object({
        prefix: z.string(),
        key: z.string(),
        separator: z.string().optional()
      })).optional(),
      // Added compose based on usage in aws.ts
      compose: z.record(z.string()).optional() 
    });
    
    export type DynamicInventoryOptions = z.infer<typeof DynamicInventorySchema>;
  • Registers the 'aws_dynamic_inventory' tool in the toolDefinitions map, linking to its description, input schema, and handler function.
    aws_dynamic_inventory: {
      description: 'Create AWS dynamic inventory',
      schema: aws.DynamicInventorySchema,
      handler: aws.dynamicInventoryOperations,
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states 'Create' which implies a write operation, but doesn't clarify if this is a one-time generation, persistent storage, or real-time query. No information on permissions, rate limits, side effects, or output format is given, making it inadequate for a tool with complex parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly. However, this conciseness comes at the cost of detail needed for such a complex tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (5 parameters with nested objects, no output schema, and no annotations), the description is insufficient. It doesn't explain what a dynamic inventory is, how it's used (e.g., for Ansible or automation), what the output looks like, or how parameters interact. For a tool with rich input schema but zero schema descriptions, more context is essential.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for all 5 parameters. It mentions 'AWS dynamic inventory' but doesn't explain what parameters like 'filters', 'hostnames', 'keyed_groups', or 'compose' do or how they relate to inventory creation. The description adds minimal meaning beyond the schema, failing to clarify parameter roles or usage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Create AWS dynamic inventory' restates the tool name with minimal elaboration. It specifies a verb ('Create') and resource ('AWS dynamic inventory'), but doesn't explain what a 'dynamic inventory' is or how it differs from static inventory tools like 'list_inventory' among siblings. The purpose is somewhat clear but lacks differentiation from related tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'list_inventory' or other AWS tools (e.g., 'aws_ec2'). The description implies creation of an inventory, but it doesn't specify prerequisites, target scenarios, or exclusions, leaving the agent to infer usage from context alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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-sysoperator'

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