DrupAnsible is a comprehensive Ansible-based deployment automation tool designed specifically for Drupal applications. It streamlines the deployment process to remote servers, providing a reliable and repeatable workflow for both staging and production environments.
- π Automated Deployments: Deploy to staging and production with simple commands
- π Secure: Vault-encrypted sensitive data and SSH key-based authentication
- π¦ Asset Management: Optional file synchronization between local and remote
- ποΈ Database Management: Automated backups, imports, and updates
- π§ Configuration Management: Drupal configuration import and update handling
- π Translation Support: Automatic locale module management and translation updates
- β»οΈ Rollback Support: Quick rollback to previous releases when needed
- π§Ή Cleanup: Automated management of old releases and database backups
Before getting started, ensure the following prerequisites are met:
- Ansible (version 2.9 or higher) installed on your local machine
- Ansistrano Deploy role installed
- Installation guide: Ansistrano-deploy
- Python 3.11 on the remote server (configured in
ansible.cfg) - PyMySQL for database operations
- SSH access to remote servers with proper authentication
- Basic understanding of Drupal project structure and deployment processes
- Drush installed in your Drupal project
drupansible/
βββ ansible.cfg # Ansible configuration
βββ vault_pass.txt # Vault password file (DO NOT commit)
βββ LICENSE # MIT License
βββ README.md # This file
βββ ansible/
βββ assets/
β βββ images/ # Documentation images
βββ core/
βββ live-deploy.yml # Production deployment playbook
βββ stage-deploy.yml # Staging deployment playbook
βββ rollback.yml # Rollback playbook
βββ inventories/
β βββ production/ # Production environment config
β β βββ inventory.yml
β β βββ group_vars/
β β β βββ deploy_vars.yml
β β β βββ server.yml
β β β βββ vars.yml
β β βββ host_vars/
β β βββ live.yml
β βββ stage/ # Staging environment config
β βββ inventory.yml
β βββ group_vars/
β β βββ deploy_vars.yml
β β βββ server.yml
β β βββ vars.yml
β βββ host_vars/
β βββ stage.yml
βββ tasks/
βββ after-update-code-tasks.yml
βββ ansistrano_after_symlink_tasks_file.yml
βββ before-cleanup-tasks.yml
βββ before-symlink-shared-tasks.yml
βββ before-symlink-tasks.yml
Production environment deployment with the following configuration:
- Uses rsync for efficient file transfer
- Excludes development files (.git, node_modules, etc.)
- Manages shared files and directories
- Integrates with production inventory and variables
Staging environment deployment with:
- Same deployment strategy as production
- Separate configuration for staging server
- Optional basic authentication support
- Uses staging-specific settings
Quick rollback to previous release:
- Uses Ansistrano rollback role
- Restores previous working version
- Maintains database integrity
This project leverages the following technologies:
- Ansible - Automation engine
- Ansistrano Deploy - Capistrano-like deployment for Ansible
- webfer.drupal_settings - Drupal settings generation role
- Python 3.11 - Interpreter for remote execution
- MySQL/MariaDB - Database management
- PyMySQL - Python MySQL client library
This project is designed to be used in combination with the MCP Ansible-Drupal Model Context Protocol server.
The MCP Ansible-Drupal server provides an automated way to install and manage DrupAnsible within your Drupal projects, offering seamless integration and simplified deployment workflows.
To install and use DrupAnsible:
- Set up the MCP Ansible-Drupal server
- Follow the installation instructions in the MCP repository
- Use the MCP tools to automatically install and configure DrupAnsible in your Drupal project
β The MCP server will handle the installation, configuration, and setup of the deployment structure for you.
After installation, your project will have the following structure:
your-drupal-project/
βββ ansible/
β βββ core/
β βββ inventories/
β β βββ production/
β β β βββ inventory.yml
β β β βββ group_vars/
β β β βββ deploy_vars.yml # Deployment configuration
β β β βββ server.yml # Server settings (vaulted)
β β β βββ vars.yml # Environment variables
β β βββ stage/
β β βββ inventory.yml
β β βββ group_vars/
β β βββ deploy_vars.yml
β β βββ server.yml
β β βββ vars.yml
β βββ live-deploy.yml
β βββ stage-deploy.yml
βββ ansible.cfg # Ansible configuration
βββ vault_pass.txt # Vault password (KEEP SECURE!)
Main Ansible configuration with:
- Python 3.11 interpreter path
- Vault password file location
- SSH connection settings
- Log file location (
ansible/tmp/logs/)
Contains the password to encrypt/decrypt sensitive variables. Never commit this file to version control!
Define your server hosts:
inventories/production/inventory.yml- Production serversinventories/stage/inventory.yml- Staging servers
Encrypted sensitive data in server.yml files:
vault_database_name- Database namevault_database_user- Database usernamevault_database_password- Database passwordvault_database_port- Database portvault_server_root_path- Server root directoryvault_server_client- Client identifiervault_server_domain- Domain namevault_server_group- Server group ownershipvault_theme_name- Drupal theme namevault_keep_releases- Number of releases to keepvault_backup_keep_count- Number of database backups to keepvault_htpasswd_user- Basic auth username (staging)vault_htpasswd_pass- Basic auth password (staging)vault_project_root- Project root path on server
The MCP Ansible-Drupal server provides tools to manage vault-encrypted configuration files securely. You can edit encrypted variables for both staging and production environments through the MCP interface.
For manual editing, you can use Ansible Vault commands directly if needed.
Deployments are managed through the MCP Ansible-Drupal server, which provides an intuitive interface for executing deployments.
The MCP server supports the following deployment configurations:
| Option | Description |
|---|---|
| Environment | Choose between staging or production |
| Mode | install (initial deployment) or update (subsequent updates) |
| Assets | Option to synchronize assets folder (files) with --delete flag |
Use the MCP Ansible-Drupal tools to perform your initial deployment:
- Deploy to staging with database import
- Optionally include asset synchronization
- Basic authentication can be configured for staging
- Deploy to production with database import
- Optionally include asset synchronization
- Uses production-specific configuration
For subsequent deployments after the initial setup:
- Use the MCP tools to deploy updates
- Configuration changes are automatically imported
- Database updates are applied
- Optional asset synchronization available
Refer to the MCP Ansible-Drupal documentation for detailed usage instructions.
- Generates Drupal
settings.phpfile using webfer.drupal_settings role - Creates public files directory (
web/sites/default/files) - Creates private files directory (
private) - Copies environment-specific settings files (stage/live)
- Database Backup: Creates timestamped MySQL dump
- Backup Cleanup: Keeps only the 5 most recent backups
- Permissions: Sets correct ownership and permissions for:
- Release directory (755)
- Files directory (755)
- Vendor directory (755)
- Web root directory (755)
- Config sync directory (755)
- Database Operations (with
db_updatetag):- Extracts SQL file from gzip archive
- Imports database using PyMySQL
- Basic Authentication (with
authtag for staging):- Creates
.htpasswdfile - Modifies
.htaccessfor authentication
- Creates
- Asset Deployment (with
deploy_assetstag):- Syncs files using rsync with
--deleteflag
- Syncs files using rsync with
- Clears Drupal cache
- Configuration Import (with
import_configtag):- Imports Drupal configuration from sync directory
- Database Updates (with
updatedbtag):- Runs pending database updates
- Clears Drupal cache again
- Translation Management (with
translationstag):- Checks if locale module is enabled
- Enables locale module if needed
- Checks for translation updates
- Updates translations
- Identifies old releases (beyond retention limit)
- Changes ownership of old releases
- Sets permissions for safe deletion
- Ansistrano then removes old releases
The following files and directories are excluded from deployment:
.ddev/
.DS_Store
.editorconfig
.git
.gitattributes
.gitignore
vault_pass.txt
installer.sh
LICENSE
.prettierrc
README.md
bitbucket-pipelines.yml
.vscode
web/sites/default/files
web/themes/custom/{theme_name}/node_modules
web/sites/default/settings.ddev.php
web/sites/default/settings.local.php
If something goes wrong, you can quickly rollback to the previous release using the MCP Ansible-Drupal tools.
The rollback functionality will restore the previous symlinked release without touching the database, ensuring a safe recovery to the last known working version.
Refer to the MCP Ansible-Drupal documentation for rollback instructions.
Ansible execution logs are stored in:
ansible/tmp/logs/ansible-latest.log
Monitor the deployment process output for:
- β Green: Successful tasks
- π‘ Yellow: Changed tasks
- π΄ Red: Failed tasks
The MCP Ansible-Drupal server allows you to run specific parts of the deployment process using Ansible tags. This gives you fine-grained control over deployment operations.
Available tag operations:
- Database import (
db_update) - Import database only - Configuration import (
import_config) - Import Drupal configuration only - Translation updates (
translations) - Update translations only - Deploy assets (
deploy_assets) - Synchronize files only - Basic authentication (
auth/auth_cleanup) - Add or remove staging authentication
Refer to the MCP Ansible-Drupal documentation for instructions on executing tag-specific deployments.
Key settings in ansible.cfg:
- Python Interpreter: Uses Python 3.11 from
/opt/alt/python311/bin/python3 - Roles Path:
ansible/core/.roles - SSH Configuration: Pipelining enabled, host key checking disabled
- Connection Retries: 3 attempts with 60s keep-alive
- Vault: Password file at
vault_pass.txt
- Never commit
vault_pass.txtto version control - Always encrypt sensitive variables using Ansible Vault
- Use SSH keys for authentication (configured in inventory)
- Limit access to vault password files
- Review
.gitignoreto ensure secrets are excluded - Rotate credentials regularly
- Use basic auth on staging environments to prevent public access
- Keep backups of database dumps in secure locations
Problem: SSH connection fails
- Solution: Verify SSH configuration in your inventory files
- Check that SSH keys are properly configured
- Ensure the remote server is accessible
- The MCP Ansible-Drupal tools will help diagnose connection issues
Problem: Vault decryption fails
- Solution: Verify
vault_pass.txtexists and contains the correct password - Check file permissions on the vault password file
- Use the MCP tools to validate vault configuration
Problem: Database import fails
- Solution: Check database credentials in vault-encrypted files
- Verify PyMySQL is installed on the remote server
- Ensure database permissions are correct
- Review the Ansible logs for detailed error messages
Problem: Permission denied errors
- Solution: Verify ownership and permissions on deployment directories
- Ensure the Ansible user has proper permissions
- Check that the server group is correctly configured
Problem: Configuration import conflicts
- Solution: Check Drupal configuration sync directory status
- Review configuration differences using Drush
- Resolve conflicts before deployment
- Export current configuration if needed
- Ansible Documentation
- Ansistrano Deploy Documentation
- Drupal Configuration Management
- Drush Commands
- Internal Wiki: Ansible-Drupal
This Ansible application is specifically designed to streamline Drupal deployments to remote servers with the most common server configurations, providing a tailored solution for efficient and reliable deployment workflows.
We encourage you to explore and utilize this application for your deployment needs. If you find it beneficial and wish to contribute to its development, your participation would be greatly appreciated. By collaborating, we can enhance the functionality and robustness of this application, benefiting the broader community and fostering a spirit of shared innovation.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
- Organization: webfer
- Repository: drupansible
Made with β€οΈ for streamlined Drupal deployments
