https://github.com/javadtorabikh/devopsansible
A hybrid intelligent system for automated web cluster management and backup on VMware ESXi
https://github.com/javadtorabikh/devopsansible
admin-server ansible docker gitlab server
Last synced: 6 months ago
JSON representation
A hybrid intelligent system for automated web cluster management and backup on VMware ESXi
- Host: GitHub
- URL: https://github.com/javadtorabikh/devopsansible
- Owner: JavadTorabiKh
- License: mit
- Created: 2025-04-28T11:06:36.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-06-28T08:06:52.000Z (7 months ago)
- Last Synced: 2025-06-28T09:24:27.723Z (7 months ago)
- Topics: admin-server, ansible, docker, gitlab, server
- Language: Python
- Homepage:
- Size: 76.2 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Ansible Infrastructure Automation ๐
Welcome to the Ansible Infrastructure Automation project! This repository provides a robust framework for managing server infrastructure using Ansible, integrated with a GitLab CI/CD pipeline for automated linting, testing, and deployment. Whether you're setting up Docker, installing base packages, or configuring DNS, this project has you covered with a modular and scalable design.

## โจ Features
- Dynamic Inventory: Uses a Python script (env_inventory.py) to generate server lists from environment variables, eliminating static host files.
- Modular Roles: Organized roles for Docker and base package installation, with Molecule tests for validation.
- CI/CD Pipeline: Automated linting, testing, planning, and applying changes via GitLab CI.
- DNS Management: Dedicated playbook for DNS configuration.
- Error Handling: Retries and artifact logging for robust pipeline execution.
## ๐ Prerequisites
To use this project, ensure the following are set up:
1. Python 3 and pip:
- Install Python 3 and pip:
```bash
dnf install python3-pip # For Rocky Linux
apt install python3-pip # For Ubuntu
```
2. Docker Engine:
- Install Docker CE following the official instructions: https://docs.docker.com/engine/install/
3. SSH Key Distribution:
- Copy the runner's public SSH key to managed servers:
```bash
Copy the runner's public SSH key to managed servers:
cat ~/.ssh/id_rsa.pub | ssh @ 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'
```
4. GitLab Environment Variables:
- Define server details in GitLab CI/CD Settings โ Variables (e.g., SERVER1_DATA, SERVER2_DATA).
- Format: See ansible/inventory/env_inventory.py for details.
## ๐๏ธ Repository Structure
```plain
DevOpsAnsible/
โโโ .gitlab-ci.yml # Enhanced CI/CD pipeline
โโโ README.md # Updated documentation
โโโ CHANGELOG.md # Version history
โโโ LICENSE # MIT/Apache license
โโโ .ansible-lint # Linting rules
โโโ requirements.txt # Python deps
โโโ tests/ # Test directory
โ โโโ molecule/ # Molecule tests
โ โโโ test-requirements.txt # Test dependencies
โโโ ansible/
โโโ ansible.cfg # Config
โโโ requirements.yml # Galaxy roles
โโโ vault.yml # Encrypted secrets
โโโ inventory/
โ โโโ production/
โ โ โโโ hosts # Prod hosts
โ โ โโโ group_vars/
โ โ โโโ all.yml # Common vars
โ โ โโโ docker.yml # Docker-specific
โ โ โโโ gitlab.yml # GitLab-specific
โ โโโ staging/
โ โ โโโ hosts
โ โ โโโ group_vars/
โ โโโ env_inventory.py # Dynamic inventory
โโโ playbooks/
โ โโโ site.yml # Master playbook
โ โโโ docker.yml # Docker setup
โ โโโ gitlab.yml # GitLab setup
โ โโโ monitoring.yml # Enhanced monitoring
โ โโโ backups.yml # Backup system
โ โโโ security.yml # Security hardening
โ โโโ maintenance.yml # Maintenance tasks
โโโ roles/
โโโ common/ # Enhanced common
โ โโโ tasks/
โ โ โโโ main.yml
โ โ โโโ packages.yml
โ โ โโโ security.yml
โ โ โโโ users.yml
โ โ โโโ tuning.yml
โ โโโ handlers/
โ โโโ templates/
โ โโโ defaults/
โโโ docker/ # Enhanced Docker
โ โโโ tasks/
โ โ โโโ main.yml
โ โ โโโ install.yml
โ โ โโโ config.yml
โ โ โโโ compose.yml # Docker Compose
โ โ โโโ networks.yml # Network config
โ โโโ templates/
โ โ โโโ daemon.json.j2
โ โ โโโ docker-compose.yml.j2
โ โโโ defaults/
โ โโโ vars/
โโโ gitlab/ # Enhanced GitLab
โ โโโ tasks/
โ โ โโโ main.yml
โ โ โโโ install.yml
โ โ โโโ config.yml
โ โ โโโ runners.yml # CI runners
โ โ โโโ backup.yml # GitLab backup
โ โโโ templates/
โ โ โโโ gitlab.rb.j2
โ โ โโโ backup.sh.j2
โ โโโ defaults/
โ โโโ vars/
โโโ monitoring/ # Enhanced monitoring
โ โโโ tasks/
โ โ โโโ main.yml
โ โ โโโ node_exporter.yml
โ โ โโโ cadvisor.yml # Container monitoring
โ โ โโโ alerts.yml # Alert rules
โ โโโ templates/
โ โโโ defaults/
โโโ backups/ # Enhanced backups
โ โโโ tasks/
โ โ โโโ main.yml
โ โ โโโ setup.yml
โ โ โโโ gitlab.yml
โ โ โโโ docker.yml
โ โโโ templates/
โ โโโ defaults/
โโโ security/ # New security role
โโโ tasks/
โ โโโ main.yml
โ โโโ firewall.yml
โ โโโ ssh_hardening.yml
โ โโโ audits.yml
โโโ templates/
โโโ defaults/
```
## ๐ Getting Started
1. Clone the Repository:
```bash
git clone https://github.com/JavadTorabiKh/DevOpsAnsible.git
cd DevOpsAnsible
```
2. Set Up GitLab CI:
- Configure environment variables in GitLab CI/CD Settings โ Variables.
- Ensure your runner has access to the target servers via SSH.
3. Run Locally (Optional):
- Install dependencies:
```bash
pip3 install --user ansible ansible-lint yamllint molecule molecule-docker docker
ansible-galaxy install -r ansible/requirements.yml
```
4. Run the main playbook:
```bash
ansible-playbook ansible/playbooks/main.yml -i ansible/inventory/env_inventory.py
```
## ๐ ๏ธ CI/CD Pipeline
The GitLab CI pipeline automates the following stages:
| Stage | Description |
|---------|---------|
| lint | Runs yamllint and ansible-lint to ensure code quality. |
| test | Executes Molecule tests for roles in parallel (e.g., docker, packages_base). |
| check_config | Simulates and applies DNS configuration changes. |
| plan | Simulates changes for the main playbook (--check --diff). |
| apply | Applies changes manually to target servers. |
## Artifacts
- Logs are stored as artifacts for 1 week to debug failures.
- Use the GitLab UI to trigger the apply stage manually.
## ๐งช Testing with Molecule
Each role (docker, packages_base) includes Molecule tests:
- Navigate to ansible/roles//molecule/default/.
- Run tests:
```bash
cd ansible/roles/docker
molecule test
```
## ๐ ๏ธ Customization
- Add New Roles: Create a new directory under ansible/roles/ with tasks/main.yml and defaults/main.yml.
- Extend Inventory: Update env_inventory.py to support additional server attributes.
- Modify Pipeline: Adjust .gitlab-ci.yml to add new stages or jobs.
## ๐ Notes
- Ensure environment variables are securely stored in GitLab.
- Review ansible.cfg for custom Ansible settings (e.g., timeouts, SSH options).
- For large deployments, consider using a custom Docker image with pre-installed dependencies to reduce pipeline runtime.
## ๐ค Contributing
Contributions are welcome! Please:
1. Fork the repository.
2. Create a feature branch (git checkout -b feature/awesome-feature).
3. Commit changes (git commit -m 'Add awesome feature').
4. Push to the branch (git push origin feature/awesome-feature).
5. Open a pull request.
## ๐ง Contact
For questions or support, reach out via [GitLab Issues](/issues) or [email](javadtorabi462@gmail.com).
---
Powered by Ansible and GitLab CI/CD