🚀 Ansible Real-World Automation Project

 LEMP Stack Automation & LEMP ➜ LAMP Migration on AWS EC2

In real production environments, manual server configuration is risky, slow, and error-prone.
 This project demonstrates how
Ansible can be used to automate a complete LEMP stack setup and later migrate it safely to a LAMP stack, exactly the way DevOps engineers do in real companies.

This is not a demo project — it reflects real-world automation and migration practices.





Why This Project Matters (Industry Perspective)

Most beginners only install services manually or automate a single task.
 In contrast, this project focuses on:

  • Infrastructure automation using Ansible
  • Variable-driven configuration (production best practice)
  • Safe web-server migration without downtime
  • Idempotent and repeatable deployments

This is the kind of automation interviewers expect from a DevOps engineer.

Tech Stack Used

  • Ansible — Configuration Management
  • Linux (Amazon Linux / RHEL) — Target OS
  • Nginx — Web Server (LEMP)
  • Apache httpd — Web Server (LAMP)
  • MariaDB — Database
  • PHP / PHP-FPM — Application Layer
  • AWS EC2 — Cloud Infrastructure

📌 Project Architecture 


🚀 Project 1: LEMP Stack Installation Using Ansible Variables

Objective

Automate the complete LEMP stack installation using Ansible variables, making the playbook reusable and scalable.

What the Playbook Does

  1. Connects to the EC2 server
  2. Defines variables for:
  • Packages
  • Services
  • File paths
  1. Installs required packages
  2. Starts and enables services
  3. Deploys a PHP test file

Why Variables Are Important

Using variables allows:

  • Easy environment changes (dev / test / prod)
  • Clean and readable playbooks
  • No hard-coding inside tasks

This is a production-grade DevOps practice.

▶ Key Code Snippet

vars:
web_package: nginx
db_package: mariadb105-server
php_pkg:
- php
- php-fpm

Now the same playbook can be reused by simply changing variable values.

Result

  • Nginx running successfully
  • PHP-FPM enabled
  • MariaDB active
  • PHP page accessible via browser

This confirms that LEMP stack is fully functional.


Project 2: Migrating from LEMP to LAMP Using Ansible

🎯 Real-World Scenario

Companies often migrate from Nginx to Apache due to:

  • Legacy application compatibility
  • .htaccess support
  • Organization standards

This project automates that migration safely.

Migration Flow

  1. Stop Nginx service
  2. Disable Nginx permanently
  3. Install Apache (httpd)
  4. Start and enable Apache
  5. Deploy new web content
  6. Verify output in browser

▶ Key Migration Logic

- name: stop nginx service
ansible.builtin.systemd:
name: nginx
state: stopped

This avoids port 80 conflict before Apache starts.

Result

  • Nginx fully disabled
  • Apache running successfully
  • Website served via Apache
  • Migration completed without manual steps

Browser output confirms:

“Migrated from LEMP to LAMP using Ansible”

▶ How to Run the Playbooks

ansible-playbook lemp_with_var.yml
ansible-playbook lemp_into_lamp.yml

🔗 Project Links