Get a practice Ansible Lab in 1 step -- Powered by Docker
Tags: beginners, docker, ansible, bash
Published: 2024-01-19 09:47:27

## Table of Contents
1. [Why This Project?](#why-this-project)
2. [Project Goals](#project-goals)
3. [Documentation](#documentation)
   - [Docker Ansible Lab Configuration](#docker-ansible-lab-configuration)
   - [Prerequisites](#prerequisites)
   - [Usage Instructions](#usage-instructions)
      - [Control-Host Usage](#control-host-usage)
      - [Server Usage (Example for Server-1)](#server-usage-example-for-server-1)
4. [Conclusion and Useful Links](#conclusion-and-useful-links)

## Why This Project?

The motivation behind this Docker Ansible Lab project is to eliminate the headaches associated with creating a lab environment for Ansible practice. The traditional setup demands a robust machine capable of running at least three VMs, with various configurations such as network establishment and SSH communication. This project aims to simplify the process by allowing users to set up a scalable lab environment within Docker, with minimal configuration requirements.

## Project Goals

The primary goal of the Docker Ansible Lab project is to enable users to effortlessly set up a lab environment within a Docker container. Unlike traditional setups, this project offers scalability, allowing users to create more than three machines with ease. The emphasis here is on minimizing the setup steps and allowing users to dive straight into Ansible without worrying about the intricacies of lab configuration.

## Documentation

### Docker Ansible Lab Configuration

**Note:** This configuration will create a total of five nodes, including three Ubuntu and two Oracle Linux machines. Refer to the `docker-compose.yaml` file for details.

**Node Credentials:**
- Username: **_zero_**
- Password: **_\][poiuy_**

### Prerequisites

Before getting started, ensure the following prerequisites are met:
- Docker installed on your machine
- Docker Compose installed
- Docker daemon started
- For Ubuntu, consider adding your user to the `docker` group
- Optionally, install the provided version (refer to the screenshot below) of higher

![Docker Ansible Setup](https://github.com/stanleyogada/docker-ansible-env-setup/assets/102979724/4bb5d9b6-4818-4a9a-ae61-4366663deedd)

### Usage Instructions

1. Clone the repository and navigate to it.
2. Run `docker-compose up -d`.
3. View the logs using `docker-compose logs -f`.
4. Wait for approximately 1-5 minutes until you see a message indicating "SUCCESS! ... Happy hacking!"
5. Your Ansible lab is now ready!

### Control-Host Usage

1. Open a new terminal for each control host.
2. Run `docker container exec -it control-host bash`.
3. Stay as the root user.
4. In the container, navigate to `cd ~/ansible-project` as this is your base Ansible directory.
5. Your lab is ready! You can now control and configure all servers. Test server connections with `ansible all -m ping`.

### Server Usage (Example for Server-1)

1. Open a new terminal for each server.
2. Run `docker container exec -it server-1 bash`.
3. Switch to the `zero` user by running `su - zero` and use the password `\][poiuy`.

## Conclusion and Useful Links

Simplify your Ansible learning journey with this Docker Ansible Lab setup, and enjoy a seamless and scalable environment for honing your skills. For further engagement, you can connect with me on [LinkedIn](https://www.linkedin.com/in/stanley-ogada/). Additionally, explore the project on [GitHub](https://github.com/stanleyogada/docker-ansible-env-setup) for more details and updates (Please star this project 🙏 ). Happy hacking!