Skip to main content
Glama

run_playbook

Execute Ansible playbooks using the MCP SysOperator server to manage infrastructure, automate tasks, and customize deployments with additional variables, inventory control, and targeted operations.

Instructions

Run an Ansible playbook

Input Schema

NameRequiredDescriptionDefault
extraVarsNo
inventoryNo
limitNo
playbookYes
tagsNo

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "extraVars": { "additionalProperties": {}, "type": "object" }, "inventory": { "type": "string" }, "limit": { "type": "string" }, "playbook": { "minLength": 1, "type": "string" }, "tags": { "type": "string" } }, "required": [ "playbook" ], "type": "object" }

Implementation Reference

  • The handler function `runPlaybook` that validates paths, builds the ansible-playbook command with options like inventory, extraVars, tags, limit, and executes it using execAsync.
    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 `RunPlaybookSchema` defining the input parameters: 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, specifying description, schema, and handler.
    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