Browse the project source code in my github repository: https://github.com/rnowotniak/ansiblelab

ansiblelab

Personal Ansible playground (based on Docker, Docker-composer, Centos8)

Contact: Robert Nowotniak rnowotniak@gmail.com

Tested on ArchLinux as the Docker host.

Quick start

Download the image from my Dockerhub account, and clone this from my github (which allows to rebuild the same image yourself from scratch):

docker pull rnowotniak/ansiblelab
git clone https://github.com/rnowotniak/ansiblelab

Create ssh keys which will be used to communicate betwen the master and the nodes in your new Ansible lab:

cd ansiblelab
ssh-keygen -q -N "" -f keys/ansiblekey

Start the containers with docker-compose per the definitions in docker-compose.yml:

docker-compose up

compose-up

Working with the lab environment

Having the master and the nodes up and running (docker-compose up), you can enter the master container and run Ansible commands on the nodes. A very basic configuration (ansible.cfg) and inventory (“inventory” file) is already copied there in the working directory.

There are 5 hosts in the default inventory (ansiblelab_node_1, …, ansible_node_5). To target hosts 1, 2 and 3 with Ansible ping module, run:

ping3

With just 3 nodes containers present, ping module will show error on 2 nodes if all 5 from the inventory are targetted:

ping5

To scale the number of hosts to 5 manually, you can use “docker-compose up -d –scale node=5” command as follows:

scale-to-5

Run some shell command (Ansible “shell” module) on all 5 nodes from the inventory (query the host hostname, executive user ID, and uname):

shell5

To shutdown gracefully and cleanup everthing:

shutdown

A few useful commands

Some Ansible modules:

Example playbook YAML file:

---
- name: My playbook
  hosts: ansiblelab_node_*
  tasks:
    - name: get /etc/hostname file
      fetch:
        src: /etc/hostname
        dest: /tmp/fetched

Books:

Links: