Website Deployment on NGINX using Ansible Project Overview
This project demonstrates how to automate the deployment of a static web application on AWS EC2 instances using Ansible playbooks with NGINX. The deployment process includes:
Installing NGINX and unzip package.
Removing old/default website files.
Downloading a website zip file from a URL.
Unzipping the files and copying them to /var/www/html/.
Restarting NGINX to serve the site.
The playbook ensures that the website can be deployed reliably and repeatedly with a single command.
Prerequisites
AWS Account – for creating EC2 instances.
Ansible Installed on your control node.
SSH access from the control node to target EC2 instances.
Public URL for website zip (e.g., organic-1.0.0.zip).
Architecture Control Node (Ansible) ---> Target Node(s) (EC2 Instances with NGINX)
Control Node: Runs Ansible playbook commands.
Target Node(s): EC2 instances where the static website will be deployed.
Steps
- Launch EC2 Instance(s)
Go to AWS EC2 console and launch Ubuntu instance.
Assign security group with inbound rules:
SSH (port 22) from your control node.
HTTP (port 80) for NGINX.
Note the public IP of the instance(s).
- Connect Control Node to Target EC2 using .ssh
Place your .pem file on the control node, e.g., ~/.ssh/mykey.pem. if dont have just create mkdir -p ~/.ssh/
Set permissions for the key:
chmod 400 ~/.ssh/mykey.pem
Add target node(s) to your inventory.ini:
[webservers] ec2-1 ansible_host=<EC2_PUBLIC_IP> ansible_user=ubuntu ansible_ssh_private_key_file=/path/to/mykey.pem
-
Playbook: playbook.yml Check the playbook.yml file for the code
-
Run the Playbook ansible-playbook -i inventory.ini playbook.yml
The playbook will:
-
Install NGINX and unzip if not present.
-
Remove old files in /var/www/html/.
-
Download and unzip the website.
-
Copy files to the web server folder.
-
Restart NGINX.
- Verify Deployment
Open the EC2 public IP in a browser:
http://<EC2_PUBLIC_IP>/
You should see your static website live.
Notes
Ensure NGINX default HTML files are removed before copying your website.
unarchive requires unzip to be installed on target nodes.
You can deploy to multiple EC2 instances simultaneously by adding them in inventory.ini.