check_syntax
Validate Ansible playbook syntax without execution to detect errors and ensure correct structure before deployment.
Instructions
Check syntax of an Ansible playbook without executing it
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"playbook": "<playbook>"
},
"name": "check_syntax"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playbook | Yes |
Implementation Reference
- The handler function for the check_syntax tool that runs 'ansible-playbook --syntax-check' on the specified playbook path.
export async function checkSyntax(options: CheckSyntaxOptions): Promise<string> { const playbookPath = validatePlaybookPath(options.playbook); // Build command with syntax-check option const command = `ansible-playbook ${playbookPath} --syntax-check`; try { // Execute command const { stdout, stderr } = await execAsync(command); return stdout || 'Syntax check passed (no issues found)'; } catch (error) { // Handle exec error - in this case, a syntax error const execError = error as { stderr?: string; message: string }; throw new AnsibleExecutionError( `Syntax error: ${execError.message}`, execError.stderr ); } } - Zod schema for check_syntax tool input, requiring a 'playbook' path string.
export const CheckSyntaxSchema = z.object({ playbook: z.string().min(1, 'Playbook path is required'), }); export type CheckSyntaxOptions = z.infer<typeof CheckSyntaxSchema>; - src/sysoperator/index.ts:65-69 (registration)Registers the check_syntax tool in the toolDefinitions object, specifying its description, schema, and handler.
check_syntax: { description: 'Check syntax of an Ansible playbook without executing it', schema: CheckSyntaxSchema, handler: playbooks.checkSyntax, },