What is EC2?
Amazon EC2 provides virtual servers in AWS. For Ansible labs you need:
- 1 control node — Ansible installed here
- 2+ managed nodes — targets Ansible configures
Laptop
↓ SSH (PEM)
Control Node (Ansible)
↓ SSH (passwordless)
Managed Node 1
Managed Node 2
Launch instances
- Open AWS Console → EC2 → Launch instance
- AMI: Ubuntu Server (LTS)
- Instance type:
t2.micro/t3.micro(Free Tier ok for learning) - Create or select a key pair (download the
.pem) - Security group inbound:
- SSH
22from your IP (required) - HTTP
80if you will test Nginx in the browser
- SSH
- Launch and note public IPs
Key pair
A key pair is how you SSH into Ubuntu EC2:
- Private key =
.pemon your laptop (never commit to Git) - Public key = installed on the instance by AWS at launch
chmod 400 ~/Downloads/control-node.pem
ssh -i ~/Downloads/control-node.pem ubuntu@<CONTROL_PUBLIC_IP>Public IP vs Elastic IP
| Public IP | Elastic IP |
|---|---|
| Changes if you stop/start | Stays the same while allocated |
| Fine for short labs | Better for stable demos |
Private IP
Used for traffic inside the VPC. Prefer private IPs between control and managed nodes when they share a VPC and you do not need public SSH to every managed host.
Lab server layout
| Role | Example name | Notes |
|---|---|---|
| Control | ansible-control | Install Ansible here |
| Managed | prod-managed-node-1 | Target |
| Managed | prod-managed-node-2 | Target |
Connect and verify
chmod 400 control-node.pem
ssh -i control-node.pem ubuntu@<IP>
uname -a
sudo apt updatePractical tasks
- Create 1 control + 2 managed Ubuntu instances
- Confirm SSH from laptop to each with the correct
.pem - Open security group SSH only to your IP
- Record public IPs for inventory later
Do not open SSH (22) to 0.0.0.0/0 longer than a short lab. Restrict to your IP.