Using Ansible to Manage Docker Containers

Ansibledox Project Understanding
Project Purpose
Ansibledox is a practical learning environment for Ansible automation that uses Docker containers to simulate a multi-host infrastructure. It demonstrates how to deploy services and manage configurations across a group of hosts using Ansible playbooks.
The GIT repositosy can be found here: https://github.com/soyroberto/ansibledox/tree/main
Architecture Overview
Infrastructure Layer
•6 Docker containers running Ubuntu (ubuntu0-ubuntu5)
•SSH access via localhost on different ports (2222-2228)
•Root access with password authentication
•Isolated environments for safe experimentation
Ansible Layer
•Inventory management with logical host grouping
•Vault integration for secure credential storage
•Modular playbooks for different services and configurations
•Group-based targeting for selective deployments
Organizational Structure
Key Features
1. Host Grouping Strategy
•pair_1: ubuntu0, ubuntu1 (ports 2222-2223)
•pair_2: ubuntu2, ubuntu3 (ports 2224-2225)
•pair_3: ubuntu4, ubuntu6 (ports 2226, 2228)
•ubuntu_pairs: Parent group containing all pairs
2. Security Implementation
•Ansible vault for password encryption
•SSH key-based authentication support
•Privilege escalation (become: yes) for administrative tasks
3. Service Deployment Examples
•cowsay: Fun command-line tool installation
•zsh: Shell environment configuration
•lolcat: Text colorization utility
•Test tools: SSH and connectivity validation
4. Automation Patterns
•Package installation and updates
•Configuration file management
•Service configuration and startup
•User environment customization
Use Cases
Learning Environment
•Safe space to practice Ansible without affecting production systems
•Immediate feedback through container isolation
•Reproducible scenarios for training
Development Testing
•Test playbooks before production deployment
•Validate automation logic across multiple hosts
•Debug inventory and group configurations
CI/CD Integration
•Automated testing of infrastructure code
•Validation of deployment procedures
•Integration testing for multi-host applications
Technical Benefits
Scalability
•Easy to add more containers/hosts
•Flexible grouping for different scenarios
•Modular playbook design for reusability
Maintainability
•Clear separation of concerns
•Standardized playbook structure
•Version-controlled infrastructure code
Security
•Encrypted credential storage
•Isolated test environments
•No impact on production systems
Subscribe to my newsletter
Read articles from Roberto Yop directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Roberto Yop
Roberto Yop
I'm technology-geek person, in love with almost all things tech from my daily job in the Cloud to my Master's in Cybersecurity and the journey all along.