This Ansible project automates the setup of Debian servers with Docker and system optimizations for containerized workloads.
This playbook collection performs the following tasks:
- Basic System Setup: Configures timezone, locale, and essential system services
- Docker Installation: Installs Docker CE with compose plugin and configures user permissions
- Linux Tuning: Optimizes system parameters for Docker and high-performance workloads
- Sets system timezone (default: Asia/Bangkok)
- Enables systemd-timesyncd for time synchronization
- Configures UTF-8 locale
- Updates package cache and installs essential packages
- Installs Docker CE from official repository
- Installs Docker Compose plugin
- Adds specified user to docker group
- Enables and starts Docker service
- Configures Docker daemon settings
- Reduces swap usage (vm.swappiness = 10)
- Increases file watch limits for development tools
- Optimizes network and memory parameters
- Configures system limits for containerized workloads
.
├── site.yml # Main playbook that imports all others
├── basic-setup.yml # Basic system configuration
├── install-docker.yml # Docker installation and setup
├── linux-tuning.yml # System performance tuning
├── inventory.ini.example # Example inventory file
├── inventory.ini # Your inventory file (create from example)
└── README.md # This file
- Ansible: Version 2.9 or higher
- Target Servers: Debian 10 (Buster) or higher
- SSH Access: Passwordless SSH access to target servers
- Sudo Privileges: User must have sudo access on target servers
Download this playbook collection to your Ansible control machine.
Copy the example inventory file and customize it:
cp inventory.ini.example inventory.iniEdit inventory.ini with your server details:
[dev]
dev-server-ip ansible_user=your_username
[staging]
staging-server-ip ansible_user=your_usernameYou can override default variables by editing the playbook files or creating a group_vars directory:
# Example variables you can customize
timezone: "Asia/Bangkok" # Set your timezone
docker_user: "your_username" # User to add to docker groupExecute the complete setup on all Debian hosts:
ansible-playbook -i inventory.ini site.ymlYou can run specific parts of the setup:
# Basic system setup only
ansible-playbook -i inventory.ini basic-setup.yml
# Docker installation only
ansible-playbook -i inventory.ini install-docker.yml
# System tuning only
ansible-playbook -i inventory.ini linux-tuning.ymlRun on specific environments:
# Run on dev servers only
ansible-playbook -i inventory.ini site.yml --limit dev
# Run on staging servers only
ansible-playbook -i inventory.ini site.yml --limit stagingTest the playbook without making changes:
ansible-playbook -i inventory.ini site.yml --checkKey variables you can customize:
| Variable | Default | Description |
|---|---|---|
timezone |
Asia/Bangkok |
System timezone |
docker_user |
{{ ansible_user }} |
User to add to docker group |
docker_gpg_url |
Docker official GPG | Docker repository GPG key URL |
Use tags to run specific tasks:
# Run only sysctl tuning tasks
ansible-playbook -i inventory.ini linux-tuning.yml --tags sysctl
# Skip Docker installation
ansible-playbook -i inventory.ini site.yml --skip-tags dockerAfter running the playbooks, verify the installation:
# Check Docker installation
docker --version
docker compose version
# Verify Docker service is running
sudo systemctl status docker
# Test Docker without sudo (may require re-login)
docker run hello-world
# Check system tuning
sysctl vm.swappiness
sysctl fs.inotify.max_user_watches-
Permission Denied for Docker: Log out and back in after running the playbook to refresh group membership.
-
SSH Connection Issues: Ensure your SSH key is added to the target server and the user has sudo privileges.
-
Package Installation Fails: Check internet connectivity and ensure the target server can reach package repositories.
Run with verbose output for troubleshooting:
ansible-playbook -i inventory.ini site.yml -vvv- The playbooks are idempotent - safe to run multiple times
- All tasks require sudo privileges on the target servers
- Docker installation uses the official Docker repository for latest stable versions
- System tuning parameters are optimized for containerized workloads
Feel free to customize these playbooks for your specific needs. Consider:
- Adding additional system packages
- Customizing Docker daemon configuration
- Adding security hardening tasks
- Including monitoring tools setup
This project is provided as-is for educational and operational use.