Ansible Development Environment Setup
This Ansible playbook automates the setup of development environments across multiple machines.
🏗️ Architecture
Host Groups
dev: Development machines (devVM, bottom, debianDesktopVM)gitea: Gitea serverportainer: Portainer container managementhomepage: Homepage dashboardansible: Ansible control node
Roles
Core Roles
maintenance: System updates, package cleanup, and rebootsbase: Core system packages, security tools, and system hardeningdevelopment: Development tools (git, nodejs, build-essential, python3)shell: Shell configuration (zsh + oh-my-zsh + powerlevel10k)docker: Docker CE installation and user configurationssh: SSH server and firewall configurationuser: User management
Application Roles
applications: Desktop applications (Brave, LibreOffice, Redshift, Evince)snap: Snap daemon and snap applications (VSCode, Cursor)
🚀 Usage
Prerequisites
# Install required collections
ansible-galaxy collection install -r collections/requirements.yml
Vault Password Setup
Host variables are encrypted with Ansible Vault. You have two options:
Option 1: Vault Password File (Recommended)
Create a vault password file:
# Create the vault password file
echo "your_vault_password" > ~/.ansible-vault-pass
chmod 600 ~/.ansible-vault-pass
Option 2: Interactive Password Prompt
Use --ask-vault-pass with each command to be prompted for the vault password.
Basic Setup
# Run on all development machines (with vault password file)
ansible-playbook dev-playbook.yml
# Run on all development machines (interactive vault password)
ansible-playbook dev-playbook.yml --ask-vault-pass
# Run on specific host
ansible-playbook dev-playbook.yml --limit devVM
# Skip reboots for specific host
ansible-playbook dev-playbook.yml --limit bottom
Selective Execution with Tags
# Security-related roles only
ansible-playbook dev-playbook.yml --tags security
# Development tools only
ansible-playbook dev-playbook.yml --tags development,docker
# Applications only
ansible-playbook dev-playbook.yml --tags apps
# Skip maintenance
ansible-playbook dev-playbook.yml --skip-tags maintenance
Skip Reboots
Add skip_reboot=true to host variables:
[dev]
bottom ansible_host=10.0.10.156 ansible_user=beast skip_reboot=true
Debug Output
Control debug information display with the ansible_debug_output variable:
# Default: No debug output (clean, production-ready output)
ansible-playbook dev-playbook.yml --limit devVM
# Enable debug output (shows detailed status information)
ansible-playbook dev-playbook.yml --limit devVM -e "ansible_debug_output=true"
# Set permanently in group_vars/all.yml
ansible_debug_output: true
Dry Run
# Check what would be changed
ansible-playbook dev-playbook.yml --check
# Verbose output
ansible-playbook dev-playbook.yml -v
🔧 Configuration
Global Variables (group_vars/all.yml)
timezone: System timezone (default: UTC)locale: System locale (default: en_US.UTF-8)ansible_debug_output: Show debug information (default: false)fail2ban_bantime: Ban duration in secondsfail2ban_findtime: Time window for failuresfail2ban_maxretry: Max failures before ban
Host Variables (host_vars/)
skip_reboot: Skip automatic reboots- Encrypted variables for sensitive data
🛡️ Security Features
Fail2ban Configuration
- SSH brute force protection
- Configurable ban times and retry limits
- Email notifications (configured in template)
UFW Firewall
- Deny-by-default policy
- SSH access allowed
- Automatic enablement
System Hardening
- Timezone and locale configuration
- Security package installation
- Monitoring tools (htop, iotop, nethogs, logwatch)
📦 Installed Packages
Base System
htop,curl,wget,unzip,xclipnet-tools,ufw,fail2baniotop,nethogs,logwatch
Development Tools
git,nodejs,npmbuild-essential,python3,python3-pip
Applications
brave-browser,libreoffice,evince,redshiftcode(VSCode),cursor(via snap)
Docker
- Docker CE with all components
- Docker Compose
- User added to docker group
🔄 Maintenance
Automatic Updates
The maintenance role handles:
- Package updates (
apt upgrade) - Unused package removal (
apt autoremove) - Cache cleanup (
apt autoclean) - Conditional reboots
Manual Maintenance
# Update only maintenance role
ansible-playbook dev-playbook.yml --tags maintenance
# Skip maintenance
ansible-playbook dev-playbook.yml --skip-tags maintenance
🐛 Troubleshooting
Common Issues
-
SSH Connection Issues
- Check
ansible.cfgSSH settings - Verify host keys and user permissions
- Check
-
Package Installation Failures
- Run with
-vfor verbose output - Check internet connectivity on target hosts
- Run with
-
Reboot Issues
- Use
skip_reboot=truefor problematic hosts - Check maintenance role handlers
- Use
Debug Commands
# Test connectivity
ansible dev -m ping
# Check facts
ansible dev -m setup
# Run specific role
ansible-playbook dev-playbook.yml --tags base
📝 File Structure
ansible/
├── ansible.cfg # Ansible configuration
├── hosts # Inventory file
├── dev-playbook.yml # Main development playbook
├── group_vars/
│ └── all.yml # Global variables
├── host_vars/ # Host-specific variables
└── roles/
├── maintenance/ # System maintenance
├── base/ # Core system setup
├── development/ # Development tools
├── shell/ # Shell configuration
├── docker/ # Docker installation
├── ssh/ # SSH configuration
├── user/ # User management
├── applications/ # Desktop applications
└── snap/ # Snap applications
🤝 Contributing
- Test changes with
--checkfirst - Update documentation for new roles/tasks
- Use proper handlers for service restarts
- Follow existing naming conventions
Description
Languages
Makefile
45.4%
Python
22.3%
Shell
18%
Jinja
14.3%