This repository contains the code and demo for the Ansible Assignment - 202, showcasing an automated web server deployment using Ansible on AWS EC2 instances. π₯οΈβοΈ
Configure two VMs (VM1 and VM2) either on your own hardware or in a cloud environment. Use Ansible to deploy a web server on both VMs running on port 8080 with a web page that displays:
- "Hello World from VM-1" on VM1
- "Hello World from VM-2" on VM2
Include Ansible tasks for deployment and cleanup. Submit a Word document with screenshots, a demo, and all Ansible code/scripts via GitHub. πΈπ
- Create three EC2 instances:
- π₯οΈ Ansible Control Node (to run Ansible)
- π VM1 & VM2 (to deploy web servers)
- Configure inbound rules for VM1 & VM2:
- β Allow HTTP traffic on port 80
- β Enable SSH access as needed
- Log into each EC2 instance.
- On the Ansible control node, add the private key:
mkdir -p ~/.ssh && chmod 700 ~/.ssh echo "PRIVATE_KEY_CONTENT" > ~/.ssh/ansible_key chmod 600 ~/.ssh/ansible_key
- Create an inventory file at
/etc/ansible/hosts:[nodes] VM1_Public_IP VM2_Public_IP - Set the SSH private key path in Ansible configuration:
ansible_ssh_private_key_file=~/.ssh/ansible_key
- Develop an Ansible playbook to:
- π¦ Install Nginx
- π§ Change Nginxβs default port to 8080
- π Deploy a custom index.html file
- π Restart Nginx
- Run the playbook:
ansible-playbook deploy_nginx.yml
- β
Verify the web pages are accessible at:
http://VM1_Public_IP:8080http://VM2_Public_IP:8080
- Create another playbook to:
- π Stop Nginx
- β Uninstall Nginx
- ποΈ Remove configuration files
- Execute cleanup:
ansible-playbook remove_nginx.yml
π Congratulations! We've successfully automated the deployment and cleanup of a web server using Ansible! ππ₯