This repository contains an Ansible playbook and role to install and configure Docker and Docker Compose on both Ubuntu and CentOS systems.
The goal of this project is to provide a reusable, production-ready Ansible setup that:
- Installs Docker CE and Docker Compose.
- Supports Ubuntu (Debian family) and CentOS (RedHat family).
- Uses idempotent tasks and handlers for services.
- Can be extended with monitoring, Kubernetes, and other DevOps tools.
.
βββ ansible.cfg
βββ inventory.ini # List of hosts/groups
βββ roles.yml # Main playbook including roles
βββ roles/
βββ docker/ # Role for Docker installation
βββ tasks/
β βββ main.yml
β βββ install_ubuntu.yml
β βββ install_centos.yml
βββ handlers/
β βββ main.yml
οΏ½οΏ½ββ defaults/
βββ main.yml # Variables (Docker versions, URLs, etc.)bash
## Supported Platforms
- Ubuntu (Debian-family)
- CentOS / RHEL (RedHat-family)
## Usage
1. Clone the repository:
```bash
git clone https://github.com/Palachev/ansible-docker.git
cd ansible-docker
- Edit inventory.ini to define your target hosts:
[linux]
ubuntu1 ansible_host=<IP_ADDRESS>
ubuntu2 ansible_host=<IP_ADDRESS>
centos1 ansible_host=<IP_ADDRESS>
Run the playbook:- Run the playbook:
ansible-playbook -i inventory.ini roles.yml --ask-become-pass-
--ask-become-pass will prompt for the sudo password.
-
The playbook detects the OS family and executes appropriate tasks automatically.
You can modify default variables in roles/docker/defaults/main.yml:
docker_version
docker_compose_version
Repository URLs, etc.
β
Handlers
Tasks notify the handler Restart docker whenever Docker is installed or updated.
The handler runs only when changes occur, ensuring idempotent behavior.
π‘ Extending the Playbook This role can be extended to:
Add monitoring (Grafana, Prometheus)
Deploy Kubernetes clusters
Automate container migrations
Configure alerts and backups
π License MIT License (or your preferred license)