Day 59: Ansible Project 🔥 (Jan 24, 2024)

🙏 Introduction:
In this blog, we will deploy a simple web app using ansible.
🎯Task: 1
- Three EC2 instances are created that include Ansible master node and Ansible servers.

- Create the ansible repository in the master
sudo apt-add-repository ppa:ansible/ansible

- Update the master node
sudo apt update

- Install Ansible in the master node
sudo apt install ansible

- Copy the private key that you have created while creating Ansible master node and Ansible servers

- Create an ansible key file in .ssh directory and store the copied private key

- Give access permission for the ansible_key
sudo chmod 700 ansible_key

- Update the inventory file
[servers]
host_1 ansible_host=52.39.126.158
host_2 ansible_host=35.89.144.134
[all:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_user=ubuntu
ansible_ssh_private_key_file=/home/ubuntu/.ssh/ansible_key

- Create a file with name install_nginx.yml
---
- name: Install Nginx
hosts: all
become: yes
tasks:
- name: Update apt
apt:
update_cache: yes
- name: Install Nginx
apt:
name: nginx
state: latest
- name: Start and enable Nginx service
service:
name: nginx
state: started
enabled: yes

- Run the the ansible-playbook
ansible-playbook install_nginx.yml

- Create a webpage index.html file in the master node
<!DOCTYPE html>
<html>
<h1>Hello Guys , Welcome to my page</h1>
<h2>This is a sample webpage</h2>
</html>

- Update the ansible-playbook
---
- name: Install Nginx
hosts: all
become: 'yes'
tasks:
- name: Update apt
apt:
update_cache: 'yes'
- name: Install Nginx
apt:
name: nginx
state: latest
- name: Start and enable Nginx service
service:
name: nginx
state: started
enabled: 'yes'
- name: Deploy webpage
copy:
src: /home/ubuntu/index.html
dest: /var/www/html/index.html
- Run the the ansible-playbook
ansible-playbook install_nginx.yml

- Login to the Ansible-Server1 to check the webpage

- Login to the Ansible-Server2 to check the webpage

About the author
Hey there! I'm currently working as an Associate DevOps Engineer, and I'm diving into popular DevOps tools like Azure Devops,Linux, Docker, Kubernetes,Terraform and Ansible. I'm also on the learning track with AWS certifications to amp up my cloud game. If you're into tech collaborations and exploring new horizons, let's connect!
Comments
Join the discussionNo comments yet. Be the first to comment.




