generate_ansible_playbook
Generate Ansible playbooks to deploy agents across Windows, Linux, and macOS platforms for endpoint management and forensic investigation workflows.
Instructions
Generate Ansible playbook for agent deployment.
Creates a complete Ansible role with tasks for all selected platforms.
Args: deployment_id: The deployment to generate playbook for include_windows: Include Windows deployment tasks include_linux: Include Linux deployment tasks include_macos: Include macOS deployment tasks labels: Labels to apply to deployed agents
Returns: Path to generated playbook directory and usage instructions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deployment_id | Yes | ||
| include_windows | No | ||
| include_linux | No | ||
| include_macos | No | ||
| labels | No |
Implementation Reference
- The `generate_ansible_playbook` tool function in `src/megaraptor_mcp/tools/deployment.py`. It uses `AnsiblePlaybookGenerator` to create an Ansible role for Velociraptor agent deployment.
async def generate_ansible_playbook( deployment_id: str, include_windows: bool = True, include_linux: bool = True, include_macos: bool = True, labels: Optional[list[str]] = None, ) -> list[TextContent]: """Generate Ansible playbook for agent deployment. Creates a complete Ansible role with tasks for all selected platforms. Args: deployment_id: The deployment to generate playbook for include_windows: Include Windows deployment tasks include_linux: Include Linux deployment tasks include_macos: Include macOS deployment tasks labels: Labels to apply to deployed agents Returns: Path to generated playbook directory and usage instructions. """ try: from ..deployment.agents import AnsiblePlaybookGenerator from ..deployment.agents.ansible_gen import AnsibleConfig from ..deployment.security import CertificateManager from ..deployment.deployers import DockerDeployer # Get deployment info deployer = DockerDeployer() info = await deployer.get_status(deployment_id) if not info: return [TextContent( type="text", text=json.dumps({ "error": f"Deployment not found: {deployment_id}", "hint": "Use list_deployments tool to see available deployments" }, indent=2) )] # Load certificates cert_manager = CertificateManager() bundle = cert_manager.load_bundle(deployment_id) if not bundle: return [TextContent( type="text", text=json.dumps({ "error": "Certificate bundle not found" }, indent=2) )] # Create Ansible config config = AnsibleConfig( server_url=info.server_url.replace("/api/", "") + ":8000/", ca_cert=bundle.ca_cert, ca_fingerprint=bundle.ca_fingerprint, client_labels=labels or ["ansible-deployed"], deployment_id=deployment_id, ) # Generate playbook generator = AnsiblePlaybookGenerator() result = generator.generate( config, include_windows=include_windows, include_linux=include_linux, include_macos=include_macos, ) return [TextContent( type="text", text=json.dumps({ **result.to_dict(), "usage": [ "1. cd " + str(result.output_dir), "2. cp inventory.yml.example inventory.yml", "3. Edit inventory.yml with your hosts", "4. ansible-playbook -i inventory.yml deploy_agents.yml", ], }, indent=2) )] except ImportError as e: return [TextContent( type="text", text=json.dumps({ "error": f"Missing dependency: {str(e)}", "hint": "Install required packages with: pip install megaraptor-mcp[deployment]" }, indent=2) )] except Exception: # Generic errors - don't expose internals return [TextContent( type="text", text=json.dumps({ "error": "Operation failed", "hint": "Check deployment configuration and try again" }, indent=2) )]