Ansible MCP Server
Ansible MCP servers enable AI models to interact with Ansible, providing capabilities for infrastructure automation, configuration management, and application deployment.
Overview
The MCP Ansible Server is a Python-based server that allows AI models to interact with Ansible's powerful automation capabilities. It exposes Ansible utilities for managing inventories, executing playbooks, and running roles, providing a safe and structured way for AI to automate infrastructure and deployments.
Created by:
Developed by bsahane
Key Features
Playbook Execution
Execute Ansible playbooks to automate tasks and deployments
Inventory Management
Manage and query Ansible inventories for host and group information
Role Execution
Run Ansible roles for modular and reusable automation
Syntax Validation
Validate Ansible playbook syntax before execution
Available Tools
Quick Reference
| Tool | Purpose | Category |
|---|---|---|
create-playbook | Create playbooks from YAML strings or dicts | Playbook |
validate-playbook | Validate playbook syntax | Playbook |
ansible-playbook | Execute playbooks | Playbook |
ansible-task | Run ad-hoc tasks | Ad-hoc |
ansible-role | Execute roles | Role |
ansible-inventory | List inventory hosts and groups | Inventory |
Detailed Usage
ansible-playbookβΆ
Execute Ansible playbooks.
use_mcp_tool({
server_name: "ansible",
tool_name: "ansible-playbook",
arguments: {
playbook_path: "/path/to/your/playbook.yml",
inventory: "/path/to/your/inventory/hosts.ini"
}
});
ansible-taskβΆ
Run ad-hoc Ansible tasks.
use_mcp_tool({
server_name: "ansible",
tool_name: "ansible-task",
arguments: {
host_pattern: "localhost",
module: "ping"
}
});
ansible-inventoryβΆ
List inventory hosts and groups.
use_mcp_tool({
server_name: "ansible",
tool_name: "ansible-inventory",
arguments: {
inventory: "/path/to/your/inventory/hosts.ini"
}
});
Installation
{
"mcpServers": {
"ansible": {
"command": "python",
"args": [
"/path/to/mcp-ansible/src/ansible_mcp/server.py"
],
"env": {
"MCP_ANSIBLE_PROJECT_ROOT": "/path/to/your/ansible/project",
"MCP_ANSIBLE_INVENTORY": "/path/to/your/ansible/inventory/hosts.ini"
}
}
}
}
Setup:
Clone the mcp-ansible repository and install dependencies:
git clone https://github.com/bsahane/mcp-ansible.git
cd mcp-ansible
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install "mcp[cli]>=1.2.0" "PyYAML>=6.0.1" "ansible-core>=2.16.0"
pip install -e .
Then, update the command and env paths in the mcpServers configuration above to match your setup.
Common Use Cases
1. Configuration Management
Automate system configuration and package management:
use_mcp_tool({
server_name: "ansible",
tool_name: "ansible-playbook",
arguments: {
playbook_path: "/path/to/playbooks/configure_webserver.yml",
inventory: "/path/to/inventory/production.ini"
}
});
2. Infrastructure Automation
Provision and manage cloud resources:
use_mcp_tool({
server_name: "ansible",
tool_name: "ansible-playbook",
arguments: {
playbook_path: "/path/to/playbooks/provision_vms.yml",
inventory: "/path/to/inventory/cloud.ini",
extra_vars: {
cloud_provider: "aws",
region: "us-east-1"
}
}
});
3. Application Deployment
Deploy applications with rolling updates:
use_mcp_tool({
server_name: "ansible",
tool_name: "ansible-playbook",
arguments: {
playbook_path: "/path/to/playbooks/deploy_app.yml",
inventory: "/path/to/inventory/staging.ini",
tags: "deploy,restart_service"
}
});
Related Articles & Guides
Accessibility Scanner MCP Server
Accessibility Scanner MCP servers enable AI models to perform WCAG compliance checks, capture annotated screenshots, and generate detailed accessibility reports.
Auth0 MCP Server
Auth0 MCP server enables AI models to interact with Auth0 identity and access management, including applications, APIs, actions, logs, and forms.
AWS MCP Server
Interact with Amazon Web Services through your AI assistant using the AWS API MCP Server.