Day 57 - Ansible Hands-on πŸš€πŸŒŸ

Day 57 - Ansible Hands-on πŸš€πŸŒŸ

Β·

2 min read

Hello DevOps Enthusiasts! πŸ‘‹

Welcome to Day 57 of the #90DaysOfDevOpsChallenge. Today, we’re diving into some practical hands-on experience with Ansible. πŸŽ‰ Let’s get started by launching an EC2 instance and setting up Ansible to manage multiple servers. πŸ› οΈ

Learn Ansible Basics – Beginners Course | KodeKloud

πŸš€ Launch an EC2 Ansible-Master Instance

  1. Log in to your AWS Management Console.

  2. Navigate to the EC2 Dashboard and click on Launch Instance.

  3. Configure your instance (choose Ubuntu as the AMI, select instance type, etc.)

  4. Launch the instance.

πŸ”„ Clone the Ansible-Master Instance

  1. Select the instance you just launched.

  2. Click on Image and templates and then Launch more like this.

  3. Enter the name and number of instances (3).

  4. Click Launch instance. πŸš€

πŸ› οΈ Setting Up the Master Server

  1. Connect to the master server using SSH:

     ssh -i /path/to/your-key.pem ubuntu@your-master-server-ip
    
  2. Update the package list and install Ansible:

     sudo apt update
     sudo apt install ansible
    

πŸ” Configure SSH Access

  1. Copy the downloaded private key to your local machine.

  2. Create a key file in the .ssh directory and paste the copied key:

     mkdir -p ~/.ssh
     vim ~/.ssh/ansible-key
    

  3. Set appropriate permissions for the key file:

     sudo chmod 600 ~/.ssh/ansible-key
    

🌐 Connecting to the Other Servers

  1. Use SSH to connect to each of the 3 servers:

     sudo ssh -i ~/.ssh/ansible-key ubuntu@ip-address
    

πŸ“‹ Create and Verify an Inventory File

  1. Create a host file and add server information:

     vim ~/hosts
    

    Example contents of hosts:

     [server]
     ansible_server1 ansible_host=13.201.65.158
     ansible_server2 ansible_host=43.205.118.99
     ansible_server3 ansible_host=35.154.246.228
    
     [all]
     ansible_python_interpreter=/usr/bin/python3
    

  2. Verify the inventory of hosts:

     ansible-inventory --list -y -i /home/ubuntu/ansible/hosts
    

βš™οΈ Using Ansible

  1. Ping the servers to check connectivity:

     ansible all -m ping -i /home/ubuntu/ansible/hosts --private-key=~/.ssh/ansible-key
    

  2. Check memory usage on the servers:

     ansible all -a "free -h" -i ~/hosts --private-key=~/.ssh/ansible-key
    

πŸŽ‰ Conclusion

That's it for today's hands-on session with Ansible! πŸŽ‰ You’ve successfully launched an EC2 instance, cloned it, set up SSH keys, created an inventory file, and used Ansible to manage multiple servers. Keep practicing, and you’ll become an Ansible pro in no time! πŸš€

Thank you for reading! 😊 Feel free to share your experiences and any questions you have in the comments below. Happy Learning! πŸ› οΈ

Did you find this article valuable?

Support Nilkanth Mistry by becoming a sponsor. Any amount is appreciated!

Β