Skip to main content
Glama
tarnover
by tarnover

run_playbook

Execute and manage Ansible playbooks directly through the MCP server, enabling automation of tasks, inventory management, and configuration deployment with specified parameters.

Instructions

Run an Ansible playbook

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
extraVarsNo
inventoryNo
limitNo
playbookYes
tagsNo

Implementation Reference

  • The handler function that runs an Ansible playbook by constructing and executing the ansible-playbook command with provided options like inventory, extra vars, tags, and limit.
    export async function runPlaybook(options: RunPlaybookOptions): Promise<string> {
      const playbookPath = validatePlaybookPath(options.playbook);
      const inventoryPath = validateInventoryPath(options.inventory);
      
      // Build command
      let command = `ansible-playbook ${playbookPath}`;
      
      // Add inventory if specified
      if (inventoryPath) {
        command += ` -i ${inventoryPath}`;
      }
      
      // Add extra vars if specified
      if (options.extraVars && Object.keys(options.extraVars).length > 0) {
        const extraVarsJson = JSON.stringify(options.extraVars);
        command += ` --extra-vars '${extraVarsJson}'`;
      }
      
      // Add tags if specified
      if (options.tags) {
        command += ` --tags "${options.tags}"`;
      }
      
      // Add limit if specified
      if (options.limit) {
        command += ` --limit "${options.limit}"`;
      }
    
      try {
        // Execute command
        const { stdout, stderr } = await execAsync(command);
        return stdout || 'Playbook executed successfully (no output)';
      } catch (error) {
        // Handle exec error
        const execError = error as { stderr?: string; message: string };
        throw new AnsibleExecutionError(
          `Error running playbook: ${execError.message}`,
          execError.stderr
        );
      }
  • Zod schema defining the input parameters for the run_playbook tool: playbook (required), extraVars, inventory, tags, limit.
    export const RunPlaybookSchema = z.object({
      playbook: z.string().min(1, 'Playbook path is required'),
      extraVars: z.record(z.any()).optional(),
      inventory: z.string().optional(),
      tags: z.string().optional(),
      limit: z.string().optional(),
    });
    
    export type RunPlaybookOptions = z.infer<typeof RunPlaybookSchema>;
  • Registration of the run_playbook tool in the toolDefinitions map, linking schema and handler.
    run_playbook: {
      description: 'Run an Ansible playbook',
      schema: RunPlaybookSchema,
      handler: playbooks.runPlaybook,
    },
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