Skip to content

Aniruddhakharve/Ansible-Project-Nginx-Roles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 Ansible Role: Nginx Web Server Setup

This project showcases an Ansible Galaxy-style role to install, configure, and manage Nginx on a remote Linux server. It uses best practices such as handlers, variables, and a modular role-based structure perfect for learning and demonstrating real-world Ansible automation.


πŸ“ Project Structure

ansible-nginx-role/
β”œβ”€β”€ inventory.ini
β”œβ”€β”€ site.yml
└── webserver/
β”œβ”€β”€ tasks/
β”‚ └── main.yml
β”œβ”€β”€ handlers/
β”‚ └── main.yml
β”œβ”€β”€ files/
β”‚ └── index.html
β”œβ”€β”€ vars/
β”‚ └── main.yml
β”œβ”€β”€ defaults/
β”‚ └── main.yml
└── meta/
└── main.yml

πŸš€ What It Does

  • Installs Nginx
  • Deploys a custom index.html web page
  • Starts and enables Nginx service
  • Uses handlers to restart Nginx on file changes
  • Uses variables for flexibility and clean code

πŸ› οΈ Prerequisites

  • A Linux control node (e.g., Ubuntu EC2) with Python 3 and pip
  • SSH access to the target machine
  • git installed
  • ansible installed

πŸ“¦ Install Ansible

🐧 On Ubuntu/Debian:

sudo apt update
sudo apt install -y python3-pip
pip3 install ansible

βœ… Verify Ansible Installation:

ansible --version

πŸ—‚οΈ How to Use This Project πŸ”Ή 1. Clone the Repository

git clone https://github.com/Aniruddhakharve/ansible-nginx-role.git
cd ansible-nginx-role

πŸ”Ή 2. Edit Your Inventory File inventory.ini

[web]
<your_target_server_ip> ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa

Replace <your_target_server_ip> and SSH key path as per your setup.

πŸ”Ή 3. Run the Playbook

ansible-playbook -i inventory.ini site.yml

πŸ“œ Role Details

webserver/tasks/main.yml

  • Installs Nginx
  • Copies a custom HTML page
  • Notifies handler to restart Nginx

webserver/handlers/main.yml

  • Restarts Nginx when notified

webserver/vars/main.yml

nginx_web_root: /var/www/html

webserver/files/index.html

  • Contains your custom HTML content served by Nginx.

πŸ“¦ Role Directory Breakdown

Each folder inside the webserver/ role has a specific purpose:

Directory Purpose
tasks/ Contains the main list of tasks to be executed (e.g., installing nginx).
handlers/ Defines actions (like restarting services) triggered by notify.
files/ Stores static files (like index.html) to be copied to target machines.
vars/ Holds role-specific variables used in tasks (e.g., web root path).
defaults/ Contains default variables that can be overridden by the user.
meta/ Defines metadata about the role (e.g., dependencies, author info).

πŸ’‘ These folders follow the Ansible Galaxy role structure, which helps in making roles reusable, organized, and shareable.


βœ… Output Example After running the playbook, visit:

http://<your_target_server_ip>

You should see: πŸš€ Nginx Configured by Ansible Role


🧠 Skills Showcased

  • βœ… Role-based Ansible automation
  • βœ… Use of handlers, vars, defaults, and files
  • βœ… Clean, reusable infrastructure code
  • βœ… Real-world provisioning with Ansible Galaxy structure

πŸ§‘β€πŸ’» Author

Aniruddha Kharve

πŸ› οΈ MCA Graduate | Linux & DevOps Enthusiast

πŸ”— GitHub: @Aniruddhakharve


⭐ Show Your Support If you found this helpful, please

⭐ star the repo and share with fellow DevOps learners!

About

My ansible-Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages