DEV Community

Jayanth Dasari
Jayanth Dasari

Posted on

Getting Started with Ansible: From Zero to Installing Apache on AWS

Today marked a major step in my DevOps journey: I finally dove into Ansible.

As a cloud computing student, I've managed servers manually before, but I knew that to scale, I needed to learn Configuration Management. Here is a breakdown of what I learned today, moving from theory to actually deploying a web server on AWS.

  1. What is Configuration Management?
    I learned that configuration management is essentially maintaining computer systems and software in a desired, consistent state. Instead of manually updating 50 servers one by one, you write the configuration once and push it to all of them.

  2. Agent vs. Agentless
    One of the first things I clarified was the difference between tools like Chef/Puppet and Ansible.

Agent-based (Chef/Puppet): You have to install software (an agent) on every target server to manage it.

Agentless (Ansible): This is what makes Ansible so cool. It uses SSH to connect to servers. If you can SSH into a server, you can manage it with Ansible. No extra installations required on the target nodes!

  1. The Inventory File (inventory.ini) Ansible needs to know where to run commands. This happens in the inventory.ini file. I learned how to group servers so I can target specific environments.

inventory.ini

[webservers]
ubuntu@54.13.23.32

ubuntu@35.24.245.23

[dbservers]
ubuntu@172.23.24.3

  1. Passwordless Authentication (The Key to Automation) Since Ansible uses SSH, entering a password for every command would be a nightmare. I set up passwordless authentication using SSH keys:

Generated keys on my VirtualBox Ubuntu machine (Control Node).

Used ssh-copy-id -i key.pem user@ip_address to copy my public key to the AWS EC2 instance.

Now, Ansible can "talk" to the AWS server without manual intervention.

  1. Ansible Ad-Hoc Commands Before writing full playbooks, I learned about Ad-Hoc commands. These are quick, one-line commands to do something simple.

Ping all servers: ansible all -m ping

Check disk space: ansible webservers -a "df -h"

  1. The Project: Installing Apache on EC2 For the practical part of my day, I connected my local Ubuntu machine (running on VirtualBox) to an AWS EC2 instance.

Using an ad-hoc command, I updated the package index and installed the Apache web server remotely. Seeing that default Apache page load on the public IP of my EC2 instance was a huge win!

What's Next?
I touched very briefly on Playbooks today. I know they are used for configuring large numbers of instances and complex workflows, so that is my goal for tomorrow.

Have you used Ansible? Let me know your favorite ad-hoc command in the comments!
linkedin :https://www.linkedin.com/in/dasari-jayanth-b32ab9367/
github :https://github.com/JayanthDasari7?tab=repositories
medium :https://medium.com/@jayanthkumardasari786/day-12-my-first-day-with-ansible-mastering-inventory-and-ad-hoc-commands-subtitle-a-look-into-6fe9618cd555

Top comments (0)