Skip to content

ErdemOzgen/ansibleDockerLab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ANSIBLE LAB SETUP USING DOCKER

If you are looking for a quick lab setup to play with ansible then docker is the best choice. This repository contains 3 node lab setup.

Prerequisite

Lab Setup

This lab setup has 3 nodes where one node will act as controller and other 2 nodes will act as managed nodes.

NODE TYPE IMAGE IMAGE NAME CONTAINER NAME NETWORK
controller ubuntu:latest anslab/controller anscontroller anslab
Managed ubuntu:latest anslab/controller ansubuntu anslab
Managed alpine:latest anslab/alpine ansalpine anslab

Image and container configuration can be found in docker-compose.yml file.

Deploy Lab

Clone the repository to your machine.

Run the following command which will start pulling the base image's and build the containers.

$ cd ansibleDockerLab
$ docker-compose up -d

Authentication

User named ansuser will be created on all the nodes with passwordless sudo privilige. Both the root and ansuser password is set to password123.

To connect to the controller node run the following command. For any other nodes replace the container name and run the command.

$ docker container exec -it anscontroller sh

Password based authentication is also enabled. You need the IP address to SSH into the container.

$ docker network inspect anslab
$ ssh ansuser@IPaddress

Bootstrap Script

In the controller node ansible package should be installed and it will be taken care by script/bootstrap.sh.

From the controller node SSH Keypair needs to be generated and distributed to all nodes for ansible to communicate. This will also be taken by script/bootstrap.sh script which is already copied to /home/ansuser in anscontroller node.

$ docker container exec -it anscontroller sh
$ su - ansuser
$ bash /home/ansuser/bootstrap.sh

This script will also create /home/ansuser/sample_project directory and run adhoc command for validation. You should be seeing similar output if the script ran fine.

anscontroller | CHANGED | rc=0 | (stdout) PRETTY_NAME="Ubuntu 22.04 LTS"
ansubuntu | CHANGED | rc=0 | (stdout) PRETTY_NAME="Ubuntu 22.04 LTS"
ansalpine | CHANGED | rc=0 | (stdout) PRETTY_NAME="Alpine Linux v3.17"

Before creating and running any Ansible playbooks, you can run this command to ping all nodes and verify the connection:

ansible servers -m ping -i hosts

In the "sample_project" directory, you will also find an example playbook named "playbook.yml", generated by bootstrap.sh script. You can run it by using command:

ansible-playbook -i hosts playbook.yml

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published