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
Moralis MCP Server
Moralis MCP servers enable AI models to query on-chain data — wallet activity, token metrics, NFTs, and dapp usage — via the Moralis Web3 APIs.
Unity MCP Server
Unity MCP servers enable AI models to interact with the Unity Editor, providing capabilities for scene manipulation, asset management, script editing, and game development automation.
Setting up MCP Servers in Visual Studio Code
Model Context Protocol (MCP) enables AI models to interact with external tools and services through a unified interface. This guide will walk you through setting up MCP servers in Visual Studio Code to enhance your GitHub Copilot experience.