DevOps (Day: 59) Ansible Project

DevOps (Day: 59) Ansible Project

Day 59:#90DaysOfDevOpsChallenge

ยท

4 min read

Table of contents

TABLE OF CONTENTS:-

Task: Creating a WebPage through Ansible.

Ansible Playooks are Amazing as you learned yesterday. What if you deploy a simple web application with the help of Ansible tool.

Task-01

Create an EC2 instance, make sure all the 3 instances are created with same key pair.

To create 3 EC2 instances, navigate to the EC2 service and launch them.

No alt text provided for this image

Create an EC2 instance, make sure all the 3 instances are created with same key pair Diagram.

After creating the 3 EC2 instances,designate one instance as the Ansible control node (Ansible_Master) and the other two instances as managed nodes (ansible_server).

No alt text provided for this image

To create 3 EC2 instances, navigate to the EC2 service and launch them Diagram.

Install the Ansible in master server.

Connect to your EC2 instance using SSH.

No alt text provided for this image

Connect to your EC2 instance using SSH Diagram.

Add the Ansible PPA repository using the following command.

sudo apt-add-repository ppa:ansible/ansible

No alt text provided for this image

Add the Ansible PPA repository using the following command Diagram.

Update the Package using the following commands.

sudo apt update -y

Install the Ansible using the following command:

sudo apt install ansible -y

No alt text provided for this image

Update the Package using the following commands /Install the Ansible using the following command Diagram.

Once the installation is done is complete,you can check the version of Ansible using the following command:

ansible --version

No alt text provided for this image

check the version of Ansible using the following command Diagram.

Copy the private key form the local to host server (ansible_server) at (/home/ubuntu/.ssh)

Copy the private form the local.

No alt text provided for this image

Copy the private form the local Diagram.

To proceed with the setup,copy the private key to the Ansible Control node (ansible_master) by creating a new file at /home/ubuntu/.ssh and pasting the private key in that file.

No alt text provided for this image

creating a new file at /home/ubuntu/.ssh and pasting the private key in that file Diagram.

Give permissions to the private key using file using chmod command.

No alt text provided for this image

Give permissions to the private key using file using chmod diagram.

Access the inventory file using sudo nano /etc/ansible/hosts

Create inventory file at location /etc/ansible/hosts which is by default location of file. Ansible hosts file is a configuration file that contains a list of hosts or servers. Add the IP addresses of the servers also add private key file location to use for authentication are highlighted in the white colour.

No alt text provided for this image

Access the inventory file using sudo nano /etc/ansible/hosts Diagram

Create a Playbook to install the Nginx.

If you need the ansible playbook syntax you can direct copy form these link, It will be helpful and save your time.

https://theraloss.com/how-to-configure-nginx-using-ansible-on-ubuntu/

No alt text provided for this image

Create a Playbook to install the Nginx Diagram.

In this playbook, we firstly specify the name of the playbook (install the Nginx) and the hosts we want to target(servers). We also set become yes to run the tasks with the root priviligies.

First task updates the apt cache on the manages nodes using the apt module. The second task installs the latest version of the Nginx using the same module. The third task uses service module to start the nginx service by specfying the service name (nginx) and setting the state parmeter. to started.

Now let's discuss the how to run Playbook using the ansible-playbook command.

ansible-playbook file-name.yml

No alt text provided for this image

ansible-playbook file-name.yml Diagram.

To check the Status of Nginx on the 2 EC2 instances Highlight in the colour.

No alt text provided for this image

To check the Status of Nginx on the 2 EC2 instances Highlight in the colour Diagram

Now Deploy a sample webpage using the ansible playbooks.

Create a new file index.html in the playbook directory, and add some sample content.

No alt text provided for this image

Create a new file index.html in the playbook directory, and add some sample content Diagram.

Update a ansible playbook file, install_nginx.yml in the playbook directory.

No alt text provided for this image

Update a ansible playbook file, install_nginx.yml in the playbook directory. Diagram.

This playbook will copy the index.html file to the defuslt Nginx web server document root directory at /var/www/html/.

Run the Playbooks.

No alt text provided for this image

This playbook will copy the index.html file to the defuslt Nginx web server document root directory at /var/www/html/ Diagram.

Once the Playbook finishe executing,open a web browser and enter the public IP Address of one of the EC2 instance running Nginx.

Testing of the Server1:

Testing of the Server2:

No alt text provided for this image

Testing of the Server1 Testing of the Server2:

Thank you for reading!! Hope you find this helpful.

#day59challenge#90daysofdevops

Always open to suggestions..!!

~ Manoj Bhamidipati ๐Ÿ™‚

ย