Skip to main content
Glama

run_ad_hoc

Execute Ansible ad-hoc commands on specified hosts to manage infrastructure operations directly from AI assistants.

Instructions

Run an Ansible ad-hoc command against specified hosts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYes
moduleNoshell
argsNo
inventoryNo
becomeNo
extra_varsNo

Implementation Reference

  • The handler function that builds and executes the Ansible ad-hoc command using the provided options.
    export async function runAdHoc(options: RunAdHocOptions): Promise<string> {
      const inventoryPath = validateInventoryPath(options.inventory);
      
      // Build command
      let command = `ansible ${options.pattern}`;
      
      // Add module
      command += ` -m ${options.module}`;
      
      // Add module args if specified
      if (options.args) {
        command += ` -a "${options.args}"`;
      }
      
      // Add inventory if specified
      if (inventoryPath) {
        command += ` -i ${inventoryPath}`;
      }
      
      // Add become flag if needed
      if (options.become) {
        command += ' --become';
      }
      
      // Add extra vars if specified
      if (options.extra_vars && Object.keys(options.extra_vars).length > 0) {
        const extraVarsJson = JSON.stringify(options.extra_vars);
        command += ` --extra-vars '${extraVarsJson}'`;
      }
    
      try {
        // Execute command
        const { stdout, stderr } = await execAsync(command);
        return stdout || 'Command executed successfully (no output)';
      } catch (error) {
        // Handle exec error
        const execError = error as { stderr?: string; message: string };
        throw new AnsibleExecutionError(
          `Error running ad-hoc command: ${execError.message}`,
          execError.stderr
        );
      }
    }
  • Zod schema defining the input parameters for the run_ad_hoc tool, including host pattern, module, args, etc.
    export const RunAdHocSchema = z.object({
      pattern: z.string().min(1, 'Host pattern is required'),
      module: z.string().default('shell'),
      args: z.string().optional(),
      inventory: z.string().optional(),
      become: z.boolean().optional(),
      extra_vars: z.record(z.any()).optional(),
    });
    
    export type RunAdHocOptions = z.infer<typeof RunAdHocSchema>;
  • Registration of the 'run_ad_hoc' tool in the toolDefinitions map, associating it with its schema and handler function.
    run_ad_hoc: {
      description: 'Run an Ansible ad-hoc command against specified hosts',
      schema: RunAdHocSchema,
      handler: adHoc.runAdHoc,
    },
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 the action but doesn't mention critical details like whether this requires specific permissions, if it's destructive, what the output format is, or any rate limits. For a tool that executes commands on hosts, this is a significant gap in transparency.

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 that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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 complexity of running ad-hoc commands (with 6 parameters, no output schema, and no annotations), the description is incomplete. It doesn't cover parameter meanings, behavioral traits, or usage context, making it inadequate for an agent to effectively select and invoke this tool.

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?

The schema description coverage is 0%, so the description must compensate by explaining parameters, but it adds no meaning beyond the schema. It doesn't clarify what 'pattern', 'module', 'args', etc., represent in the context of Ansible ad-hoc commands, leaving all 6 parameters semantically unclear.

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

Purpose4/5

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

The description clearly states the verb 'Run' and the resource 'Ansible ad-hoc command against specified hosts', making the purpose understandable. However, it doesn't explicitly differentiate this tool from its sibling 'run_playbook', which is a closely related Ansible operation, so it doesn't reach the highest score.

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 like 'run_playbook' or other sibling tools. It lacks context about prerequisites, typical use cases, or exclusions, leaving the agent with minimal direction.

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