DEV Community

Cover image for Get a practice Ansible Lab in 1 step -- Powered by Docker
Stanley Chinedu Ogada
Stanley Chinedu Ogada

Posted on • Updated on

Get a practice Ansible Lab in 1 step -- Powered by Docker

Table of Contents

  1. Why This Project?
  2. Project Goals
  3. Documentation
  4. 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

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. Additionally, explore the project on GitHub for more details and updates (Please star this project 🙏 ). Happy hacking!

Top comments (0)