Skip to main content
Glama
tarnover
by tarnover

run_ad_hoc

Execute Ansible ad-hoc commands on specified hosts with a single request, enabling immediate task execution and configuration management without full playbooks.

Instructions

Run an Ansible ad-hoc command against specified hosts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNo
becomeNo
extra_varsNo
inventoryNo
moduleNoshell
patternYes

Implementation Reference

  • The main handler function that executes the Ansible ad-hoc command. It constructs the ansible CLI command from options and runs it using execAsync.
    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 validation for the run_ad_hoc tool parameters.
    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(),
    });
  • Registration of the 'run_ad_hoc' tool in the toolDefinitions object, specifying its description, input 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 mentions running commands against hosts, implying execution and potential system changes, but fails to detail critical aspects like permissions needed, side effects, error handling, or output format, leaving significant gaps for a tool with 6 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, making it highly concise and front-loaded. Every part contributes directly to stating the tool's function, though this brevity comes at the cost of detail.

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 (6 parameters, no output schema, no annotations), the description is incomplete. It doesn't cover parameter meanings, behavioral traits, or usage context, making it inadequate for an agent to reliably invoke this tool without additional guesswork or external knowledge.

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 undocumented parameters. It only vaguely references 'specified hosts' (hinting at 'pattern' or 'inventory'), but doesn't explain any of the 6 parameters (e.g., 'args', 'become', 'extra_vars'), their purposes, or how they interact, failing to add meaningful semantic value beyond the bare schema.

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 resource ('Ansible ad-hoc command against specified hosts'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'run_playbook' or 'list_tasks', which are related Ansible operations, so it misses full sibling distinction.

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' for playbooks or 'list_tasks' for task listing. It lacks context on prerequisites, exclusions, or specific scenarios, offering only a basic statement of function.

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