This project leverages Ansible to automate the configuration and deployment of both VMs and Docker containers. The structure supports multiple Linux distributions and is ideal for testing and setting up environments using VMs or Docker.
- Multi-environment Support: Works with various Linux distributions, including Debian, Ubuntu, ArchLinux, CentOS, Rocky, Suse, and Alpine.
- Ansible Playbooks: Automate the configuration of VMs or Docker containers with reusable Ansible roles.
- VM and Docker Management: Choose between managing VMs or setting up lightweight environments with Docker containers.
- Customizable Roles: Pre-defined Ansible roles for tasks such as Docker installation, NGINX configuration, SSH key management, and more.
- Simulated VM environments with Docker: Useful for testing, where Docker containers act as lightweight VM replacements.
- Ansible: For running playbooks and managing infrastructure.
- Docker: For containerized environments.
- VMWare Workstation Pro (or any virtualization software): For managing VMs.
- Python 3 and Make: Required in the Ansible VM for running playbooks.
- SSH: Ensure SSH access is configured on all target VMs.
-
Configure VMs:
- Update
src/inventory-vm.yml
with your VMs' details. - Mount the
./src
directory into the Ansible VM. - Install Ansible, Python3, and Make in the Ansible VM.
- Ensure the Ansible VM and other VMs are on the same network.
- Set up SSH access on your VMs and specify the private key in
src/ansible.cfg
.
- Update
-
Run Playbooks:
- Connect to Ansible VM, and run
make play-vm <playbook>
- Connect to Ansible VM, and run
- Step 1: Define your container setup in
./tests/<os>/service.yml
, including ports and services. - Step 2: Update the Ansible inventory in
./src/inventory.yml
with your containers. - Step 3: Run the following command to automatically generate the Docker Compose file based on your Ansible inventory:
make docker-init-all
- Step 1: Initialize the Docker setup on Debian (configured for Docker in Docker):
make docker-init-docker
- Step 2: Start your containers:
make docker-start
- Start the Docker containers:
make docker-start
- Access the Ansible container’s terminal:
make docker-cli
- Stop and remove containers and volumes:
make docker-down
- Run Ansible playbooks on your Docker containers:
make play-vm <playbook>
This Ansible project includes several playbooks to automate the setup and configuration of key services such as Chrony, Docker, NGINX, Python, and SSH across various hosts. Below is an overview of each playbook and its functionality.
-
chrony
Purpose: Configures Chrony for time synchronization.
Features:- Installs and configures Chrony for NTP services.
- Ensures that time synchronization is set up correctly across defined hosts.
-
docker
Purpose: Installs Docker and sets up a Docker Swarm cluster.
Features:- Installs Docker.
- Configures Docker daemon settings.
- Creates a Docker Swarm cluster.
- Manages Docker Swarm by gathering information, obtaining join tokens, and adding managers and workers.
- Repair a broken Docker Swarm cluster.
-
information
Purpose: Gathers information from servers.
Features:- Collects system and network information from all hosts.
- Useful for obtaining an overview of the infrastructure.
-
network_vware
Purpose: Configures network settings.
Features:- Disables specific network transmission options to resolve issues with VMWare.
-
nginx
Purpose: Installs and configures NGINX web server.
Features:- Installs NGINX on the web servers.
- Configures NGINX with custom templates.
- Runs tests to verify the NGINX setup.
-
python
Purpose: Installs Python on all servers.
Features:- Installs Python on the target hosts.
- Ensures Python is available for running other roles and tasks.
-
ssh
Purpose: Manages SSH keys and accounts.
Features:- Generates and deploys SSH keys to specified hosts.
- Creates SSH users and tests SSH connections.
You can view the Ansible inventory structure using the following commands:
- VM Inventory Graph:
make graph-vm
- Docker Inventory Graph:
make graph-docker
- Contributions to improve compatibility with other Linux distributions are welcome! Please open a pull request if you make improvements.