- In this project, I demonstrate how to automate the installation, configuration, and deployment of a static website on an Apache Web Server using Ansible Roles.
- The project follows Ansible best practices and is structured to be reusable, modular, and production-ready.
π Project Overview
The main goal of this project is to:
Automate Apache installation
Deploy a static website
Use Ansible Roles for clean structure
Implement handlers and variables
Ensure OS-based conditional execution
This project is ideal for DevOps beginners and infrastructure automation use cases.
π Tools & Technologies Used
Ansible β Configuration Management
Apache2 β Web Server
Linux (Debian-based OS)
YAML β Automation language
π Project Directory Structure
sample_role/
βββ tasks/
β βββ main.yml
βββ handlers/
β βββ main.yml
βββ vars/
β βββ main.yml
βββ files/
β βββ index.html
βββ meta/
βββ README.md
This structure follows the standard ansible-galaxy role layout.
βοΈ Role Components Explained
πΉ vars/main.yml
Defines reusable variables:
pkg: apache2
destfile: /var/www/html/
πΉ tasks/main.yml
Handles package installation and website deployment:
- name: Install apache2
package:
name: "{{ pkg }}"
state: latest
when: ansible_os_family == "Debian"
- name: Deploy static website on apache2
copy:
src: "."
dest: "{{ destfile }}"
become: yes
notify:
- start apache2
πΉ handlers/main.yml
Ensures Apache service starts only when required:
- name: start apache2
service:
name: apache2
state: started
enabled: yes
πΉ files/
Contains static website files:
- HTML
- CSS
- JavaScript
- Images
These are copied directly to Apacheβs web root directory.
βΆοΈ Playbook to Execute the Role
- hosts: all
become: yes
roles:
- sample_role
π Execution Flow
- Playbook calls the Ansible role
- Variables are loaded
- Apache is installed (Debian-based OS)
- Static website is deployed
- Handler is triggered
- Apache service starts and is enabled
β Expected Output
Apache Web Server installed successfully
Apache service running and enabled on boot
Static website accessible via browser using server IP
π Benefits of Using Ansible Roles
- Reusable automation code
- Clean and organized structure
- Easy maintenance
Faster deployments
Reduced human errors
π Conclusion
This project demonstrates how Ansible Roles can be used to build scalable and reusable infrastructure automation.
By separating tasks, handlers, variables, and files, the solution becomes production-ready and aligns with real-world DevOps practices.



Top comments (0)