Day 59: Ansible Project

Day 59: Ansible Project

Ansible playbooks are amazing, as you learned yesterday. What if you deploy a simple web app using Ansible, sounds like a good project, right?

Task-01

Create 3 EC2 instances. make sure all three are created with the same key pair.

Navigate to the EC2 service and launch three EC2 instances.

The three EC2 instances should be created, with one being designated as the Ansible control node (ansible master) and the other two as managed nodes (node1 and node2).

No alt text provided for this image

Install Ansible on the host server

Connect to your EC2 instance using SSH.

No alt text provided for this image

Add the Ansible PPA repository using the following command:

sudo apt-add-repository ppa:ansible/ansible        
No alt text provided for this image

Update the package

No alt text provided for this image

Install Ansible using the following command:

sudo apt install ansible        

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

ansible --version        
No alt text provided for this image

Copy the private key from the local to the Host server (ansible master) at (/home/ubuntu/.ssh)

Copy the private key from your local.

No alt text provided for this image

Create a new file at /home/ubuntu/.ssh, paste the private key in it, and then continue with the setup by copying the private key to the Ansible control node (ansible master).

No alt text provided for this image

Give permissions to the private key file using chmod command.

No alt text provided for this image

In case of facing any error, you can elevate the permission of the key( eg: sudo chmod 666 key_name)

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

Create inventory file at location?/etc/ansible/hosts?which is by default location of the file. An Ansible hosts file is a configuration file that contains a list of hosts or servers. Add the IP addresses of the servers and also add private key file locations to use for authentication.

No alt text provided for this image

Create a playbook to install Nginx

No alt text provided for this image

In this playbook, we first give the hosts we want to target as well as the playbook's name (Install nginx). (servers). In order to start the tasks with root permissions, we also set become: yes.

The first task uses the apt module to update the apt cache on the controlled nodes. Using the same module, the second task installs the most recent version of Nginx. The third step starts the Nginx service by supplying the service name (nginx) and setting the status parameter to start using the service module.


Use the ansible-playbook command to execute a playbook.

ansible-playbook file-name.yml        
No alt text provided for this image

Check the status of Nginx on the two EC2 instances,

No alt text provided for this image

Deploy a sample webpage using the Ansible playbook

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

No alt text provided for this image

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

No alt text provided for this image

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

Run the playbook

No alt text provided for this image

Open a web browser and type the public IP address of one of the EC2 instances running Nginx after the playbook has finished running.

No alt text provided for this image

The website will be present on all the servers, so check them all!

No alt text provided for this image

You can add more layers or improvise more on your own; add this project to your résumé! Share it with your peers if it even slightly expands your understanding????

Sunil Kumar

Senior Cloud Engineer - Nagarro | Google Cloud Certified {"CDI, ACE , PCA, PDE}|Cloud DevOps Specialist | 5x GCP , Azure Certified | Devops | Linux | Docker | Terraform | Jenkins CI/CD | Kubernetes

1 年

Vinay Kumar well explained !!

Abhishek Yadav

RHCSA | RHCE | AWS | ANSIBLE | LINUX | Git | Docker | MySQL | JENKINS | KUBERNETES | TERRAFORM

1 年

Thanks for posting...??

要查看或添加评论,请登录

Vinay Kumar的更多文章

  • DevOps Project - 4 ????

    DevOps Project - 4 ????

    Project Description The project aims to deploy a web application using Docker Swarm, a container orchestration tool…

    7 条评论
  • DevOps Project 3 ????

    DevOps Project 3 ????

    Project Description The project involves hosting a static website using an AWS S3 bucket. Amazon S3 is an object…

    3 条评论
  • DevOps Project -2 ????

    DevOps Project -2 ????

    Project Description The project is about automating the deployment process of a web application using Jenkins and its…

  • Day 80: DevOps Project 1 ????

    Day 80: DevOps Project 1 ????

    Project Description The project aims to automate the building, testing, and deployment process of a web application…

    2 条评论
  • Day 73 - Setup Grafana on AWS EC2 Instance ????

    Day 73 - Setup Grafana on AWS EC2 Instance ????

    Task: Set up grafana in your local environment on AWS EC2. Go to the AWS console and Launch an EC2 instance To enable…

  • Day 72 - Grafana ????

    Day 72 - Grafana ????

    What is Grafana? No matter where your metrics are kept, Grafana is an open-source data visualization and monitoring…

    4 条评论
  • Day71 - Terraform Interview Questions ????

    Day71 - Terraform Interview Questions ????

    1. What is Terraform and how it is different from other IaaC tools? HashiCorp's Terraform is an Infrastructure as Code…

  • Day 70 - Terraform Modules ????

    Day 70 - Terraform Modules ????

    Modules are containers for multiple resources that are used together. A module consists of a collection of .

    4 条评论
  • Day 69 - Meta-Arguments in Terraform ???

    Day 69 - Meta-Arguments in Terraform ???

    When you define a resource block in Terraform, by default, this specifies one resource that will be created. To manage…

    4 条评论
  • Day 65 - Terraform Resources ????

    Day 65 - Terraform Resources ????

    Understanding Terraform Resources A resource in Terraform represents a component of your infrastructure, such as a…

    2 条评论

社区洞察

其他会员也浏览了