Sponsored by Deepsite.site

Ansible MCP Server

Created By
tarnover7 months ago
MCP for Ansible
Content

Ansible MCP Server

A Model Context Protocol (MCP) server for Ansible automation. This server allows AI assistants to interact with Ansible, execute playbooks, manage inventory, and perform other Ansible operations directly.

Features

  • Run Ansible Playbooks: Execute Ansible playbooks with support for parameters like inventory, extra vars, tags, and limits
  • List Inventory: View hosts and groups from an Ansible inventory file
  • Check Syntax: Validate Ansible playbook syntax without execution
  • List Tasks: Preview tasks that would be executed by a playbook
  • Access Default Inventory: Access the default Ansible inventory file via resource API
  • AWS Integration: Manage AWS resources using Ansible (EC2, S3, VPC, CloudFormation, etc.)
  • LocalStack Support: Test AWS operations locally using LocalStack without real AWS credentials

Requirements

  • Node.js 18 or higher
  • npm or yarn
  • Ansible installed and in PATH
  • @modelcontextprotocol/sdk (installed automatically)
  • For AWS operations: AWS CLI and valid credentials
  • For LocalStack: LocalStack installed and running, awslocal CLI

Installation

1. Clone the repository

git clone https://github.com/your-username/mcp-ansible.git
cd mcp-ansible

2. Install dependencies

npm install

3. Build the server

npm run build

4. Configure MCP settings

Add the Ansible MCP server to your MCP settings configuration file.

For VSCode with Claude extension:

  • Edit the file at ~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

For Claude Desktop app:

  • macOS: Edit ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: Edit %APPDATA%\Claude\claude_desktop_config.json
  • Linux: Edit ~/.config/Claude/claude_desktop_config.json

Add the following to the mcpServers section:

{
  "mcpServers": {
    "ansible": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-ansible/build/index.js"],
      "env": {}
    }
  }
}

Make sure to replace /absolute/path/to/mcp-ansible with the actual path to your installation.

Usage Examples

Once installed and configured, the MCP server provides the following tools to the AI assistant:

1. Run a Playbook

<use_mcp_tool>
<server_name>ansible</server_name>
<tool_name>run_playbook</tool_name>
<arguments>
{
  "playbook": "/path/to/your/playbook.yml",
  "inventory": "/path/to/inventory.ini",
  "extraVars": {
    "var1": "value1",
    "var2": "value2"
  },
  "tags": "setup,configure",
  "limit": "webservers"
}
</arguments>
</use_mcp_tool>

2. List Inventory

<use_mcp_tool>
<server_name>ansible</server_name>
<tool_name>list_inventory</tool_name>
<arguments>
{
  "inventory": "/path/to/inventory.ini"
}
</arguments>
</use_mcp_tool>

3. Check Playbook Syntax

<use_mcp_tool>
<server_name>ansible</server_name>
<tool_name>check_syntax</tool_name>
<arguments>
{
  "playbook": "/path/to/your/playbook.yml"
}
</arguments>
</use_mcp_tool>

4. List Tasks in a Playbook

<use_mcp_tool>
<server_name>ansible</server_name>
<tool_name>list_tasks</tool_name>
<arguments>
{
  "playbook": "/path/to/your/playbook.yml"
}
</arguments>
</use_mcp_tool>

5. Access Default Inventory Resource

<access_mcp_resource>
<server_name>ansible</server_name>
<uri>ansible://inventory/default</uri>
</access_mcp_resource>

6. AWS S3 Operations

<use_mcp_tool>
<server_name>ansible</server_name>
<tool_name>aws_s3</tool_name>
<arguments>
{
  "action": "list_buckets",
  "region": "us-east-1"
}
</arguments>
</use_mcp_tool>

LocalStack Integration

This project includes integration with LocalStack for testing AWS operations locally without real AWS credentials. The LocalStack integration allows you to:

  1. Test Ansible playbooks that use AWS services locally
  2. Develop and test AWS operations without incurring AWS costs
  3. Run tests without requiring real AWS credentials
  4. Validate your infrastructure code before deploying to real AWS

Using LocalStack

See the LocalStack README for detailed instructions on using the LocalStack integration.

Quick start:

# Install LocalStack and awslocal CLI
pip install localstack awscli-local

# Start LocalStack
localstack start

# Run the sample playbook
node localstack/run_sample_playbook.mjs

Development

Project Structure

mcp-ansible/
├── src/
│   ├── index.ts                  # Main entry point
│   └── ansible-mcp-server/       
│       └── index.ts              # Ansible MCP server implementation
├── localstack/                   # LocalStack integration
│   ├── README.md                 # LocalStack documentation
│   ├── sample_playbook.yml      # Sample playbook for LocalStack
│   ├── inventory.ini             # Sample inventory for LocalStack
│   ├── run_sample_playbook.mjs   # Script to run sample playbook
│   └── utils.localstack.ts       # Modified utils for LocalStack
├── package.json                  # Project configuration and dependencies
├── tsconfig.json                 # TypeScript configuration
└── README.md                     # Documentation

Adding New Features

To add new Ansible capabilities to the MCP server:

  1. Modify src/ansible-mcp-server/index.ts
  2. Add your new tool in the setupToolHandlers method
  3. Implement a handler function for your tool
  4. Rebuild with npm run build

License

MIT License - See LICENSE for details

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Playwright McpPlaywright MCP server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Serper MCP ServerA Serper MCP Server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
CursorThe AI Code Editor
WindsurfThe new purpose-built IDE to harness magic
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
ChatWiseThe second fastest AI chatbot™
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
DeepChatYour AI Partner on Desktop
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Tavily Mcp
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Amap Maps高德地图官方 MCP Server