Skip to main content
Glama
tarnover
by tarnover

aws_dynamic_inventory

Generate dynamic AWS inventory for Ansible by specifying regions, filtering resources, customizing hostnames, and grouping instances with defined keys. Streamlines infrastructure management through automated updates.

Instructions

Create AWS dynamic inventory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
composeNo
filtersNo
hostnamesNo
keyed_groupsNo
regionYes

Implementation Reference

  • Main handler function that creates an AWS EC2 dynamic inventory YAML using the amazon.aws.aws_ec2 plugin, writes it to a temporary file, runs ansible-inventory --list to display the inventory structure, and tests it with a simple ping playbook.
    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 input schema for the aws_dynamic_inventory tool defining parameters: region (required), filters, hostnames (array), keyed_groups (array of objects with prefix, key, separator), compose (object).
    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() 
    });
  • Registration of the 'aws_dynamic_inventory' tool in the toolDefinitions Record, specifying its description, input schema, and handler function.
    aws_dynamic_inventory: {
      description: 'Create AWS dynamic inventory',
      schema: aws.DynamicInventorySchema,
      handler: aws.dynamicInventoryOperations,
    },
Behavior1/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. 'Create' implies a write/mutation operation, but the description provides no information about authentication requirements, rate limits, side effects, what happens if inventory already exists, or what the tool actually produces. No behavioral traits beyond the basic 'create' action are disclosed.

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 extremely concise at just three words. While this represents under-specification rather than ideal conciseness, within the scoring framework for this dimension, it's front-loaded with the core action and wastes no words. Every word earns its place, even if more content is needed.

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

Completeness1/5

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

Given the complexity (5 parameters with nested objects, no annotations, no output schema), the description is completely inadequate. A 'create' operation with multiple complex parameters requires explanation of what's being created, how parameters interact, what authentication is needed, and what the result looks like. The three-word description provides none of this necessary context.

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?

With 0% schema description coverage for 5 parameters (region, compose, filters, hostnames, keyed_groups), the description provides no parameter information whatsoever. The schema shows complex nested objects and arrays, but the description doesn't explain what these parameters mean, how they interact, or what values are expected. The description fails to compensate for the complete lack of schema documentation.

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

Purpose3/5

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

The description states the tool 'Create AWS dynamic inventory' which provides a basic verb+resource combination. However, it's vague about what 'dynamic inventory' specifically means in this context and doesn't differentiate from sibling tools like 'list_inventory' or 'aws_ec2' which might have related functionality. The purpose is understandable but lacks specificity about what type of inventory or what makes it 'dynamic'.

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?

The description provides no guidance on when to use this tool versus alternatives. With multiple AWS-related sibling tools (aws_ec2, aws_cloudformation, etc.) and inventory-related tools (list_inventory), there's no indication of when this specific dynamic inventory creation tool is appropriate versus other inventory or AWS management tools. No context, prerequisites, or exclusions are mentioned.

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

Related 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-ansible'

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