Ansible Installation & EC2 Setup – My Practical Experience
After understanding Ansible modules and the overall architecture, the next thing I wanted to do was actually install Ansible and set up a working environment.
This is the part where theory meets hands-on practice — and honestly, this is where everything started making sense for me.
In this blog, I’ll share how I installed Ansible on a Linux EC2 instance and connected it with other EC2 servers to run automation.
⭐ Where I Installed Ansible
I installed Ansible on a Linux-based EC2 instance, which acted as my control node.
You can use:
-
Amazon Linux 2
-
Ubuntu
-
CentOS
All work fine.
I mostly used Amazon Linux 2 and Ubuntu in my practice.
๐ง Installing Ansible on Amazon Linux 2
These are the exact steps I followed:
1️⃣ Update the system
2️⃣ Install Ansible using Amazon Extras
3️⃣ Verify installation
Once I saw the version output, I knew Ansible was installed successfully.
๐ง Installing Ansible on Ubuntu (Alternative Method)
If you use Ubuntu as your controller:
Both operating systems work smoothly.
⭐ Setting Up the Managed Nodes (Target Servers)
Once Ansible was installed on the controller, I launched additional EC2 instances to use as managed nodes.
To allow Ansible to connect:
-
I kept port 22 (SSH) open
-
I ensured the private key (.pem) file was on the controller machine
-
I SSH’d into the controller and copied my key there
Example:
After that, I set correct permissions:
⭐ Creating a Custom Inventory File
This is the file where I tell Ansible which servers to manage.
I created a file named inventory.ini:
What these mean:
-
ansible_host → EC2 public IP
-
ansible_user → default login user (ec2-user / ubuntu)
-
ansible_ssh_private_key_file → key file path
This is where I finally understood how Ansible identifies and connects to servers.
⭐ Testing SSH Connectivity Using Ansible
Before running any automation, I tested connection using the ping module:
A successful output looked like:
Seeing this “pong” output gave me confidence that everything was working correctly.
๐ฆ Final Setup Flow (My Practical Workflow)
✔ Ansible installed on EC2 controller
✔ Private key copied with correct permissions
✔ Inventory file created
✔ Ping test successful
After this setup, I was ready to:
-
run ad-hoc commands
-
write playbooks
-
deploy apps
-
automate server configuration
This was the point where my real Ansible learning started.
⭐ Quick Example After Setup
Here’s the first real command I ran:
And within seconds, nginx was installed across all my servers — fully automated.
That felt like a true DevOps moment.
⭐ Final Thoughts
Setting up Ansible on a controller and connecting it to EC2 instances was a simple but powerful experience.
Once the SSH connection and inventory file were in place, everything else became very easy.
This setup is the foundation for:
-
ad-hoc commands
-
playbooks
-
inventory configurations
-
roles
-
automation workflows
In the next blog, I’ll write about:
๐ Ansible Ad-Hoc Commands
(the fastest way to run automation without creating playbooks)
Comments
Post a Comment