Day 59 - Ansible Project ??
Guduru Bharat Kumar
Aspiring DevOps Engineer | CS Graduate | Skilled in Git, Jenkins, Docker, AWS, Azure, Terraform, Bash , Python & Kubernetes
Automating Nginx Deployment on AWS EC2 Instances with Ansible
Introduction: In today's fast-paced world, automation plays a crucial role in managing and deploying applications efficiently. In this article, we will walk through the process of creating three Amazon EC2 instances, ensuring they share the same key pair, installing Ansible on the host server, and using Ansible to deploy and configure Nginx on these instances.
Step 1: Create EC2 Instances
1.1 Amazon EC2 Instance Creation:
Step 2: Install Ansible on Host Server
2.1 Accessing the Host Server:
ssh -i path/to/your-key-pair.pem ubuntu@your-host-ip
2.2 Installing Ansible:
sudo apt update
sudo apt install ansible
Step 3: Copy Private Key to Host Server
3.1 Copy Private Key:
scp -i path/to/your-key-pair.pem path/to/your-key-pair.pem ubuntu@your-host-ip:/home/ubuntu/.ssh
Step 4: Configure Ansible Inventory
4.1 Accessing Inventory File:
sudo vim /etc/ansible/hosts
4.2 Update Inventory File:
领英推荐
[web_servers]
instance1_private_ip
instance2_private_ip
instance3_private_ip
Step 5: Create Ansible Playbook for Nginx
5.1 Creating Ansible Playbook:
---
- hosts: web_servers
become: true
tasks:
- name: Install Nginx
apt:
name: nginx
state: present
- name: Start Nginx service
service:
name: nginx
state: started
5.2 Running Ansible Playbook:
ansible-playbook -i /etc/ansible/hosts nginx_install.yml
Step 6: Deploy Sample Webpage
6.1 Creating Sample Webpage:
6.2 Updating Ansible Playbook:
---
- hosts: web_servers
become: true
tasks:
- name: Install Nginx
apt:
name: nginx
state: present
- name: Start Nginx service
service:
name: nginx
state: started
- name: Deploy Sample Webpage
copy:
src: path/to/index.html
dest: /var/www/html/index.html
6.3 Run Updated Ansible Playbook:
ansible-playbook -i /etc/ansible/hosts nginx_install.yml
Conclusion: By following these steps, you have automated the deployment of Nginx on multiple EC2 instances using Ansible. This approach enhances efficiency, scalability, and maintainability in managing web server configurations.
I'm confident that this article will prove to be valuable, helping you discover new insights and learn something enriching .
thank you : )