# 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](https://github.com/soyroberto/ansibledox/tree/main)

## Architecture Overview

![alt text](https://github.com/soyroberto/ansibledox/raw/main/ansiblewdox.jpg align="left")

### Infrastructure Layer

•6 Docker containers running Ubuntu (ubuntu0-ubuntu5)

•SSH access via [localhost](http://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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751771597325/1f959d00-d18b-4c32-b1bf-13aa0510dafe.png align="center")

## 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
