Understanding Configuration Management with Ansible

Understanding Configuration Management with Ansible

Introduction

Welcome to Day 55 of my #90DaysOfDevOps journey! Today, we're diving into Configuration Management with Ansible, a powerful tool that's essential for modern DevOps practices. I'll share my hands-on experience setting up Ansible on AWS EC2 instances.

Task Overview

Our goals for today:

  1. Install Ansible on an EC2 instance (Master Node)

  2. Configure the hosts file

  3. Set up worker nodes and establish connectivity

Implementation Steps

1. Installing Ansible

After launching our EC2 instance, I installed Ansible using the following commands:

sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible

Here's what the successful installation looks like:

Ansible installation showing various Python dependencies being configured

As we can see, Ansible installed successfully with version [core 2.17.7] and all required dependencies.

2. Configuring the Hosts File

Next, I configured the Ansible inventory file:

[webservers]
node1 ansible_host=<your EC2 Private IP>
node2 ansible_host=<your EC2 Private IP>

[all:vars]
ansible_ssh_private_key_file=/home/ubuntu/.ssh/key.pem
ansible_user=ubuntu

Here's the verification of our inventory setup:

Ansible inventory configuration showing successful node setup and initial ping test

3. AWS EC2 Setup

I set up multiple EC2 instances for this configuration:

AWS Console showing our Ansible master and worker nodes

Key points from the EC2 setup:

  • ansible1 (Master Node): Running with public IP 52.201.227.157

  • ansible2 (Worker Node): Running with proper security groups

  • Both instances are t2.micro, perfect for our testing setup

Key Observations

  1. Installation Process

    • Multiple Python dependencies were automatically handled

    • Ansible core 2.17.7 was successfully installed

    • All required packages were properly configured

  2. Inventory Setup

    • Successfully configured two nodes

    • Used private IP addresses for better security

    • Proper SSH key configuration in place

  3. Connectivity Test

    • Initial SSH fingerprint verification required

    • Successful ping response from node1

    • Python interpreter automatically discovered on remote hosts

Technical Details

From our setup, we can see:

  1. Ansible Configuration

     ansible [core 2.17.7]
     config file = /etc/ansible/ansible.cfg
     python version = 3.12.3
    
  2. Node Configuration

    • Master Node Private IP: 172.31.85.116

    • Worker Node Private IP: 172.31.85.223

    • Both running on Ubuntu with proper SSH access

Challenges Faced

  1. SSH Key Management

    • Had to properly set up key permissions

    • Required correct path configuration in hosts file

  2. First Connection Issues

    • Needed to handle SSH fingerprint verification

    • Resolved Python interpreter warnings

Next Steps

After this successful setup, we can:

  1. Create and implement playbooks

  2. Set up configuration management policies

  3. Automate routine tasks

  4. Implement infrastructure as code

Learning Outcomes

This hands-on experience taught me:

  • Proper Ansible installation and configuration

  • AWS EC2 instance management

  • Network security considerations

  • SSH key management

  • Inventory file configuration

Key Takeaways

  1. Always verify installations with ansible --version

  2. Use private IPs for internal communication

  3. Properly manage SSH keys and permissions

  4. Document and verify inventory configurations

Connect & Share

Found this helpful? Let's connect! Share your Ansible experiences in the comments below.

#90DaysOfDevOps #DevOps #Ansible #AWS #TechLearning #ConfigurationManagement #Trainwithsubham


Happy Learning! Keep pushing forward on your DevOps journey!