bsahane/ansible-adv-mcp-server
If you are the rightful owner of ansible-adv-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Ansible MCP Server is a comprehensive Model Context Protocol (MCP) Server designed to enable AI assistants to manage infrastructure using Ansible.
Ansible MCP Server
A comprehensive Model Context Protocol (MCP) Server that enables AI assistants to manage infrastructure using Ansible. This server provides intelligent parsing, execution, and management of Ansible repositories with support for enterprise features and future AWX/AAP integration.
Features
š§ Infrastructure Management
- Ansible Repository Parsing: Deep understanding of ansible.cfg, inventories, group_vars, host_vars, roles, and collections
- Multi-Repository Support: Manage multiple Ansible repositories simultaneously
- Playbook Management: Create, validate, and execute Ansible playbooks with flexible YAML input
- Hardware Discovery: Comprehensive hardware scanning and inventory generation
- Security Auditing: Security scanning, port scanning, password policy audits
š¤ AI-Optimized Design
- Flexible Input: Accept YAML strings, objects, and structured data
- Comprehensive Error Handling: Detailed error reporting and recovery mechanisms
- Context Persistence: Maintain session state and context between operations
- Dynamic Tool Loading: Extensible architecture for adding new tools and services
š Cross-Platform Support
- Containerized Deployment: Docker-based deployment for consistency and scalability
- Linux Server Deployment: Primary target for server infrastructure
- Remote Server Management: Secure remote server management capabilities
š ļø MCP Tools
Git Management Tools
clone-repository
- Clone remote Ansible repositories to local projectspull-repository
- Pull updates from configured remote repositoriesremove-repository
- Remove configured repositories from projects
Ansible Core Tools
create-playbook-flexible
- Create playbooks with YAML strings or objectsansible-playbook
- Execute playbooks with --check and direct execution modesansible-task
- Execute ad-hoc Ansible tasksansible-role
- Execute existing roles, create new roles, manage dependenciesansible-collection
- Install and manage Ansible collectionsvalidate-playbook
- Validate playbook syntax and best practicescreate-role-structure
- Generate standard Ansible role directories
Infrastructure Tools
hardware-scan
- Comprehensive hardware discovery and analysisstorage-analysis
- Storage device discovery and health analysisnetwork-interfaces
- Network adapter discovery and configurationdiscover-proxmox
- Discover Proxmox VMs and containersgenerate-inventory
- Create Ansible inventories from discovery data
Security Tools
security-quick-scan
- Quick security assessmentsecurity-scan-ports
- Network port scanning and analysissecurity-check-passwords
- Password policy audit and enforcementsecurity-audit-accounts
- User account auditing and managementsecurity-check-ssh
- SSH configuration security audit
Service Management Tools
browse-services
- Browse available service catalogdeploy-service
- Deploy services from cataloglist-environments
- List available deployment environmentsdeploy-to-environment
- Deploy with environment protection
Quick Start
Prerequisites
- Node.js 18+
- Docker and Docker Compose (for containerized deployment)
- Ansible Core 2.15+ (for local development)
- Git 2.30+
Installation
Using Docker (Recommended)
- Clone the repository:
git clone <repository-url>
cd ansible-mcp-server
- Copy environment variables:
cp .env.example .env
# Edit .env with your configuration
- Start with Docker Compose:
# Production deployment
docker-compose up -d
# Development with hot reload
docker-compose --profile dev up -d ansible-mcp-dev
# With PostgreSQL
docker-compose --profile postgres up -d
Local Development
- Install dependencies:
npm install
- Copy environment variables:
cp .env.example .env
- Build and start:
npm run build
npm start
# Or for development with hot reload
npm run dev
Configuration
The server uses environment variables for configuration. See .env.example
for all available options.
Key Configuration Options
DB_TYPE
: Database type (sqlite
orpostgresql
)DB_CONNECTION
: Database connection stringANSIBLE_CONFIG
: Path to ansible.cfg fileANSIBLE_INVENTORY
: Default inventory file or directoryREPOSITORIES_PATH
: Directory for cloned repositoriesLOG_LEVEL
: Logging level (error
,warn
,info
,debug
)
Usage
MCP Client Integration
The server implements the Model Context Protocol and can be used with any MCP-compatible client:
{
"mcpServers": {
"ansible-mcp-server": {
"command": "node",
"args": ["dist/index.js"],
"env": {
"LOG_LEVEL": "info",
"DB_TYPE": "sqlite",
"DB_CONNECTION": "./data/ansible-mcp.db"
}
}
}
}
Example Tool Usage
Clone an Ansible Repository
{
"name": "clone-repository",
"arguments": {
"url": "https://github.com/example/ansible-repo.git",
"name": "my-infrastructure",
"branch": "main",
"credentials": {
"type": "token",
"token": "ghp_xxxxxxxxxxxx"
}
}
}
Create and Execute a Playbook
{
"name": "create-playbook-flexible",
"arguments": {
"content": "---\n- name: Install nginx\n hosts: webservers\n tasks:\n - name: Install nginx package\n apt:\n name: nginx\n state: present",
"path": "./playbooks/install-nginx.yml",
"validate": true
}
}
{
"name": "ansible-playbook",
"arguments": {
"playbookPath": "./playbooks/install-nginx.yml",
"inventory": "./inventory/production",
"options": {
"checkMode": true,
"diff": true,
"limit": "webservers"
}
}
}
Perform Hardware Discovery
{
"name": "hardware-scan",
"arguments": {
"hosts": "all",
"inventory": "./inventory/production",
"includeStorage": true,
"includeNetwork": true
}
}
Architecture
Core Components
- MCP Server Core: TypeScript-based MCP server implementation
- Ansible Engine: Python-based Ansible execution engine
- Repository Manager: Git and Ansible repository management
- Discovery Engine: Hardware and infrastructure discovery
- Security Scanner: Security auditing and scanning tools
- Service Catalog: Templated service deployment system
Technology Stack
- Primary Language: TypeScript (MCP Server), Python (Ansible Engine)
- Database: SQLite (default), PostgreSQL (enterprise)
- Containerization: Docker with multi-stage builds
- Logging: Winston with structured logging
- Validation: Joi for schema validation
Development
Project Structure
src/
āāā core/ # Core MCP server and tool registry
āāā services/ # Business logic services
āāā tools/ # MCP tool implementations
āāā types/ # TypeScript type definitions
āāā utils/ # Utility functions
āāā test/ # Test files
Building
# Install dependencies
npm install
# Build TypeScript
npm run build
# Run tests
npm test
# Lint code
npm run lint
# Format code
npm run format
Docker Development
# Build Docker image
npm run docker:build
# Run in container
npm run docker:run
# Development with hot reload
docker-compose --profile dev up
Security
Security Features
- Secure credential storage and management
- Role-based access control (RBAC)
- Audit logging for all operations
- Network security best practices
- Container security scanning
Security Best Practices
- Use SSH keys instead of passwords for Git authentication
- Enable audit logging in production
- Run containers as non-root user
- Use secrets management for sensitive data
- Regularly update dependencies and base images
Performance
Performance Requirements
- Sub-second response time for basic operations
- Concurrent execution of multiple playbooks
- Scalable to 1000+ managed nodes
- Efficient memory usage in containerized environments
Optimization Tips
- Use SQLite for single-instance deployments
- Use PostgreSQL for multi-instance deployments
- Configure appropriate
ANSIBLE_FORKS
for your environment - Use inventory caching for large infrastructures
- Monitor resource usage and adjust container limits
Troubleshooting
Common Issues
Server Won't Start
- Check environment variables in
.env
file - Ensure database is accessible
- Verify Node.js version (18+ required)
- Check log files for detailed error messages
Ansible Commands Fail
- Verify Ansible is installed and accessible
- Check inventory file permissions
- Validate SSH connectivity to target hosts
- Review Ansible configuration (
ansible.cfg
)
Repository Clone Fails
- Verify Git credentials are correct
- Check network connectivity
- Ensure sufficient disk space
- Review repository URL format
Debug Mode
Enable debug logging for detailed troubleshooting:
export LOG_LEVEL=debug
npm start
Or in Docker:
environment:
- LOG_LEVEL=debug
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run linting and tests
- Submit a pull request
Development Guidelines
- Follow TypeScript best practices
- Add JSDoc comments for public APIs
- Write unit tests for new features
- Update documentation for user-facing changes
- Use conventional commit messages
License
This project is licensed under the MIT License - see the file for details.
Future Enhancements
Phase 2: Enterprise Features
- AWX/Ansible Automation Platform integration
- Enterprise authentication (LDAP, SAML)
- Advanced workflow orchestration
- Custom dashboard and reporting
Phase 3: Advanced Intelligence
- AI-powered playbook optimization
- Predictive infrastructure monitoring
- Automated remediation workflows
- Cost optimization recommendations
Support
For issues and questions:
- Check the troubleshooting section
- Search existing GitHub issues
- Create a new issue with detailed information
- Join our Discord community
Acknowledgments
- Ansible for the powerful automation platform
- Model Context Protocol for the MCP specification
- TypeScript for type-safe development
- Docker for containerization support