Getting Started with Ansible: From Zero to Installing Apache on AWS
Source: Dev.to
What is Configuration Management?
Configuration management is the practice of maintaining computer systems and software in a desired, consistent state. Instead of manually updating dozens of servers one by one, you write the configuration once and push it to all of them.
Agent vs. Agentless
Agent‑based (Chef/Puppet)
You must install an agent on every target server to manage it.
Agentless (Ansible)
Ansible connects via SSH. If you can SSH into a server, you can manage it with Ansible—no extra software required on the target nodes.
The Inventory File (inventory.ini)
Ansible needs to know where to run commands. This is defined in the inventory.ini file, where you can group servers for targeted operations.
# inventory.ini
[dbservers]
# example host entry
ubuntu@172.23.24.3
Passwordless Authentication (The Key to Automation)
Since Ansible uses SSH, entering a password for every command would be impractical. Set up password‑less authentication with SSH keys:
- Generate keys on the control node (e.g., a VirtualBox Ubuntu machine).
- Use
ssh-copy-id -i key.pem user@ip_addressto copy the public key to the AWS EC2 instance.
After this, Ansible can communicate with the AWS server without manual password entry.
Ansible Ad‑Hoc Commands
Ad‑hoc commands are quick, one‑line operations useful before writing full playbooks.
-
Ping all servers:
ansible all -m ping -
Check disk space on the
webserversgroup:ansible webservers -a "df -h"
The Project: Installing Apache on EC2
For a hands‑on exercise, I connected my local Ubuntu machine (running in VirtualBox) to an AWS EC2 instance and used an ad‑hoc command to:
- Update the package index.
- Install the Apache web server remotely.
Seeing the default Apache page load on the public IP of the EC2 instance confirmed the success.
What’s Next?
I briefly explored playbooks, which are essential for configuring large numbers of instances and handling complex workflows. My next goal is to create and run full playbooks with Ansible.