Day 57: Ansible Hands-on with Video🚀🚀

Day 57: Ansible Hands-on with Video🚀🚀

Day#57 Of 90 Days Of DevOps Challenge

👋Introduction

Do you have a strong desire to gain proficiency in the efficient management of your infrastructure using Ansible?

Ansible, an open-source automation tool, empowers you to effortlessly configure, oversee, and deploy applications throughout your network.

Within this blog post, we will guide you through the fundamental procedures for establishing Ansible on an AWS EC2 instance and commencing server management.

📜Task of the Day: Create a blog post that provides an in-depth explanation of the content covered in the Ansible video

Since we have already discussed this task in previous blog posts, please make sure to refer to those. Here, we will walk you through the commands step by step.

Day 55: vishaltoyou.hashnode.dev/day-55-understandi..

Day 56: vishaltoyou.hashnode.dev/day-56-ansible-ad-..

So , let's start the walkthrough of the commands

Step 1: Creating an EC2 Instance

To begin, you need to create an EC2 instance on AWS. Make sure you have an AWS account set up and are logged into the AWS Management Console.

Step 2: Adding Ansible Repository

Once your EC2 instance is up and running, we will add the Ansible PPA repository to it. Use the following commands:

sudo apt-add-repository ppa:ansible/ansible

Step 3: Installing Ansible

Update the package list and install Ansible with the following commands:

sudo apt-get update
sudo apt-get install ansible

After the installation is complete, you can check the Ansible version to ensure it's correctly installed:

ansible --version

Step 4: Setting Up Multiple EC2 Instances

To make the most of Ansible, you'll want to manage multiple servers. Here's how you can set up two more EC2 instances with the same private key as the Ansible master instance:

  • Launch two new EC2 instances.

  • Copy the private key from the master server to where Ansible is set up.

  • Create a new file on the master server at /home/ubuntu/.ssh and paste the private key into it.

With these steps, you can SSH into the two new server instances from the master instance using the private key.

Step 5: Creating an Ansible Inventory

To manage your servers effectively, you need to create an Ansible inventory. This is a list of IP addresses that Ansible will work with.

Follow these steps to create your inventory file:

  • Create a new folder named "ansible."

  • Inside the folder, create a "hosts" file, which will serve as your inventory.

  • Add the IP addresses of the servers inside the "hosts" file.

You can verify the inventory of hosts using the ansible-inventory command:

ansible-inventory --list -y -i /path/to/your/inventory-file

Step 6: Testing Connectivity with Ansible

Before you start automating tasks with Ansible, you should ensure that your Ansible master can communicate with the remote servers. If you encounter SSH connection issues, it's likely due to authentication problems.

You can resolve this by following these steps:

  • Check the permissions on the remote host's private key file.

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

  • Specify the private key file to use for authentication when running the Ansible command:

ansible -i /path/to/inventory_file all -m ping --private-key=/path/to/private_key

In the command above, replace /path/to/inventory_file and /path/to/private_key with your actual file paths.

Step 7: Running Ad Hoc Commands

With Ansible, you can run ad hoc commands to perform various tasks. Here are a couple of examples:

  • To check free memory or memory usage of hosts:
ansible -i /path/to/inventory_file all -a "free -m"
  • To check uptime:
ansible -i /path/to/inventory_file all -a uptime

In these commands, replace /path/to/inventory_file with your inventory file's actual path.

💥Conclusion

By following these steps, you've taken the first strides in setting up Ansible on an EC2 instance, creating an inventory, and testing connectivity with your servers.

Ansible is a powerful automation tool that can simplify and streamline your infrastructure management.

With these basics in place, you can start automating your server management tasks efficiently. So, dive deeper into Ansible and discover the possibilities it offers for your infrastructure automation needs.

Happy learning & may your cloud journey be filled with exciting discoveries!🎊

Thank you for joining us on this exciting Day 57 of the 90 Days of DevOps challenge. I hope you found the information helpful and insightful.💥

So please keep yourself updated with my latest insights and articles on DevOps 🚀 by following me on :

Hashnode: vishaltoyou.hashnode.dev

LinkedIn: linkedin.com/in/vishalphadnis