Skip to main content
Glama

run_playbook

Execute Ansible playbooks to automate infrastructure configuration and management tasks through the MCP SysOperator server.

Instructions

Run an Ansible playbook

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playbookYes
extraVarsNo
inventoryNo
tagsNo
limitNo

Implementation Reference

  • The main handler function that runs the Ansible playbook by constructing and executing the ansible-playbook command with validation and error handling.
    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 path, optional extra vars, inventory, tags, and 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(), });
  • Registration of the 'run_playbook' tool in the toolDefinitions object, specifying its description, input schema, and handler function.
    run_playbook: { description: 'Run an Ansible playbook', schema: RunPlaybookSchema, handler: playbooks.runPlaybook, },

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