Skip to main content

Command Palette

Search for a command to run...

Day 57: Ansible Hands-on with video (Jan 22, 2024)

Published
2 min read
Day 57: Ansible Hands-on with video   (Jan 22, 2024)
M

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!

🙏 Introduction:

In this blog, Today we will write a blog explanation for the Ansible Tutorial for DevOps Engineers

🎯Task: 1

Write a Blog explanation for the ansible video

  • Create an EC2 instance

  • Connect to your EC2 instance using SSH

  • Add the Ansible PPA repository

  • Update the package

  • Install Ansible

  • check the version of Ansible

  • Launch three new EC2 instances with same private key as Ansible-master-node EC2 instance.

  • Copy the private key to master server where Ansible is setup

  • In master node where ansible is setup, create a new file at location /home/ubuntu/.ssh and paste private key to that file.

  • SSH into Ansible server instances from master instance by using private key
sudo ssh -i /key-path ubuntu@public-ip-address

  • Create an inventory file for Ansible that lists the IP addresses of the Ansible server

  • Create a new folder named ansible, inside folder create hosts file which is inventory file for ansible. add the IP addresses of the servers inside hosts file.

[servers]
server1 ansible_host=34.218.229.216 
server2 ansible_host=54.200.111.227
server3 ansible_host=34.216.221.116

[all:vars]
ansible_python_interpreter=/usr/bin/python3

  • To verify the inventory of hosts
ansible-inventory --list -y -i <inventory-file-path>

  • Change the private key permission (ansible_key)

  • Specify the private key file to use for authentication using the --private-key option when running the Ansible command
ansible -i <inventory_file> all -m ping --private-key=<path_to_private_key>

  • Ansible command to check the free memory
ansible -i /home/ubuntu/ansible/hosts all -a "free -m" --private-key=/home/ubuntu/.ssh/ansible_key

  • Ansible command to check uptime
ansible -i /home/ubuntu/ansible/hosts all -a "uptime" --private-key=/home/ubuntu/.ssh/ansible_key

More from this blog

DevOps Journey with M Hassan

174 posts

I am writing these blogs because I recently completed a comprehensive DevOps course where I gained in-depth knowledge of the topics mentioned. As I progressed through the course, I realized the importance of having a concise and accessible resource to revise and reinforce my understanding of each topic. Therefore, I decided to create cheat sheets in the form of blog posts. These cheat sheets will not only serve as a handy reference for myself but also benefit others who are also interested in mastering DevOps concepts. By documenting each topic and providing concise explanations, I aim to create a valuable resource that simplifies complex concepts and facilitates hands-on practice. This way, I can solidify my own understanding while helping others on their DevOps journey.