Lab 000 - Setup¶
- In this lab we will define and build docker containers which to be used in the next of labs.
- The lab structure consists of an Ansible controller & 3 Linux servers, all set inside docker containers.
01. Usage¶
- There are several ways to run the Ansible Labs.
- Choose the method that works best for you.
Killercoda (Recommended)- 🐳 Docker
- 📜 From Source
Using Google Cloud Shell
- The easiest way to get started with the labs
- Learn Ansible in your browser without any local installation
Benefits:
- No installation required
- Pre-configured environment
- Works on any device with a web browser
- All tools pre-installed
Using Docker is the easiest way to get started locally with the labs:
# Change to the Labs directory
cd Labs/000-setup
# Run the setup lab using Docker Compose
docker-compose up -d
Prerequisites:
- Docker and Docker Compose installed on your system
- No additional setup required
For those who prefer to run it directly on their machine:
# Clone the repository
git clone https://github.com/nirgeier/AnsibleLabs.git
# Change to the Labs directory
cd AnsibleLabs/Labs
# Start with the setup lab
cd 000-setup
# Follow the instructions in the README of each lab
cat README.md
- Ansible installed on your system
- A Unix-like operating system (Linux, macOS, or Windows with WSL)
- Basic command-line tools
- Google Cloud Shell provides a free, browser-based environment with all necessary tools pre-installed.
- Click on the
Open in Google Cloud Shellbutton below:
- The repository will automatically be cloned into a free Cloud instance.
- Use CTRL + click to open it in a new window.
- Follow the instructions in the README of each lab.
Benefits:
- No local installation required
- Pre-configured environment
- Works on any device with a web browser
- All tools pre-installed
- Free tier available
Lab Breakdown
- If you choose to run the labs locally using Docker or From Source, follow the steps below to set up your environment.
- Make sure you have the necessary tools installed.
- Follow the instructions in the README of each lab.
- Review the Dockerfile(s) and docker-compose.yml for container configurations.
02. Build From Source¶
- Clone the git repo:
git clone https://github.com/nirgeier/AnsibleLabs.git - Navigate to the Labs directory:
cd AnsibleLabs/Labs/000-setup - The lab contains the
docker-composefile along with the Dockerfile(s) The containers are based upon ubuntu and are published to DockerHub as well. - Build the demo containers
- The docker-compose will create
ansible-controllerwhich will server as our controller to execute ansible playbooks on our demo servers defined by the nameslinux-server-X
Labs containers
| Container | Content |
|---|---|
🐳 ansible-controller | Linux container with ansible installed |
🐳 linux-server-1 | Linux container with ssh only (no ansible installed) |
🐳 linux-server-2 | Linux container with ssh only (no ansible installed) |
🐳 linux-server-3 | Linux container with ssh only (no ansible installed) |
- For the demo we will also need a shared folder(s) where the certificates and the configuration will be stored
- The shared folder(s) will be mounted into the containers
- The containers will have access to the shared folder(s) for reading and writing files
- The shared folder(s) will be used to store the Ansible playbooks and inventory files
- The shared folder(s) will be mounted at
/labs-scriptsin the containers
03. Core Concepts¶
- Create
Ansible Controllercontainer, which will be used to manage the other containers SSH Keys- The SSH keys will be generated and mounted into the containers- Initialize servers: Set up runtime directories, start demo containers via
Docker Compose, verifyAnsibleinstallation, extractSSH keysfrom servers, configure known hosts, check SSH services, and test SSH connections to each Linux server
04. The setup script(s)¶
# Build the Ansible container & the Demo servers
# The `_setup.sh` will build all we will need for this lab
./_setup.sh
05. Setup Scripts Breakdown¶
| Script | Content |
|---|---|
🗞️ 00-build-containers.sh | 📒 Init the shared folders |
| 🐳 Build the container(s) | |
🗞️ 01-init-servers.sh | ⏯ Initialize the containers |
| 🔐 Extract the ssh certificates | |
| ✓ verify that the ssh service is running in the containers | |
🗞️ 02-init-ansible.sh | 🚀 Initialize the ansible files |
📚 ansible.cfg | |
📚 ssh.config | |
📚 inventory |
06. Verify Containers¶
$ docker ps -a
# Expected output
IMAGE PORTS NAMES
---------------------------------------------------------------------------------------------------------------------
nirgeier/ansible-controller 22/tcp ansible-controller
nirgeier/linux-server 0.0.0.0:3001->22/tcp, 0.0.0.0:5001->5000/tcp, 0.0.0.0:8081->8080/tcp linux-server-1
nirgeier/linux-server 0.0.0.0:3002->22/tcp, 0.0.0.0:5002->5000/tcp, 0.0.0.0:8082->8080/tcp linux-server-2
nirgeier/linux-server 0.0.0.0:3003->22/tcp, 0.0.0.0:5003->5000/tcp, 0.0.0.0:8083->8080/tcp linux-server-3
07. Next Steps¶
- Proceed to Lab 001 - Verify Ansible configuration to start using Ansible with the configured environment.
- Don’t forget to check the logs for any errors or issues during the setup process.
- If you encounter any problems, refer to the troubleshooting section or open an issue on the GitHub repository.
- Enjoy learning Ansible!