The system topology diagram below represents how the Ansible Control Node orchestrates host configuration management tasks, and maps the Docker Compose multi-container bridged network layout.
2. Part 1: Step-by-Step Action Items & Key Execution Steps
Install the Ansible automation engine on the control VM and map local SSH authorization parameters to bypass passphrase challenges.
$ sudo apt update && sudo apt install -y ansible
This command updates repository packages metadata lists and installs the Ansible configuration management framework tools on the guest VM workstation.
$ ssh-copy-id -i ~/.ssh/id_ed25519.pub localhost
This command appends the local public SSH key metadata block to the localhost authorized_keys list, allowing passwordless connections to the local machine.
STEP 2
Configure Ansible Inventory and Run Ad-hoc Checks
Write host target files defining destination environments and verify connectivity using basic modules.
This command writes a simple inventory configuration mapping localhost to the local group, configuring Ansible to execute commands without using SSH wrappers.
$ ansible all -i ~/Projects/hosts -m ping
This command uses the ping module to test target connectivity, returning a "pong" response to verify the setup.
$ ansible all -i ~/Projects/hosts -m shell -a "hostname"
This command runs the shell command hostname on target hosts, validating module execution and command response pipelines.
STEP 3
Install Docker Engine and Compose Plugins
Register Docker's official distribution keys, write package lists, and compile Docker Engine services.
This command creates a secure directory for cryptographic keys, downloads Docker's official GPG verification key, and imports it for package validation.
This command writes Docker's package repository entry into the source listings, ensuring the system pulls updates directly from official Docker mirrors.
This command updates package indexes to include Docker's repositories and installs the Docker runtime, command-line interface, container runtime daemon, and Compose plugins.
This command starts the Docker background service daemon immediately and registers it to automatically start up whenever the host system boots.
STEP 4
Configure Docker Groups and Verify Container Execution
Grant socket access permissions to standard accounts to run containers without needing root elevation prefixes.
$ sudo usermod -aG docker $USER
This command appends the current user account to the docker group, granting permission to read and write to the Docker UNIX socket.
$ newgrp docker
This command refreshes group associations within the active terminal session, enabling Docker socket permissions without needing to restart the shell.
$ docker run hello-world
This command downloads and runs a test image to verify that the container engine can run containers on the system.
3. Automation Architecture
The workflow diagram below outlines the automated orchestration steps. The playbook verifies target nodes, manages keys, configures engines, copy-pastes sources, and runs Docker Compose services.
4. Part 2: Complete Deliverable Assets & Production Templates
To deploy the multi-container application stack, we will write a Node.js web application, containerize it, and coordinate its services using Docker Compose. Below is a step-by-step breakdown of how these configuration files are built, followed by the final consolidated templates.
Step-by-Step Template Construction
Step 1
Declare Application Dependencies
Setup package descriptors listing the frameworks needed for the web server and database client connection.
This package.json file defines metadata for the project and specifies that Express (routing framework) and Mongoose (MongoDB object modeler) must be installed.
Step 2
Write the Web Server and Database Connection Logic
Implement routing logic and connection strings referencing the MongoDB container hostname alias.
This code initializes Express, connects to MongoDB using a dynamic connection string, sets up a home page route, and starts listening on port 3000.
Step 3
Write the Dockerfile to Containerize the Application
Define the execution image steps, copy files, run package installers, expose ports, and set execution scripts.
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
This Dockerfile specifies using a lightweight Node.js base image, sets the working directory, copies dependency files to run production installs, copies the source code, exposes port 3000, and configures the default run script.
Step 4
Write the Docker Compose Orchestration Manifest
Define database and web application service configurations, map networking routes, and configure storage volumes.
This compose file coordinates both services, sets environment variables, routes host port 3000 to the container, mounts the database volume, and connects both containers to a bridged network.
Combined Complete Configuration Files
Create these files inside your project folder (~/Projects), build, and start the services: