Learn Ansible by doing! This is a minimal setup for managing your EC2 instance from your Mac.
ansible/
README.md # You are here
ansible.cfg # Basic settings
inventory.yml # Your EC2 server info
playbook.yml # Install Nginx (your first automation!)
ANSIBLE_GUIDE.md # Complete beginner's guide
pip3 install ansible
# Check it worked
ansible --versionEdit inventory.yml and change these:
YOUR_EC2_IP→ Your actual EC2 public IP (like54.123.45.67)~/Downloads/my-key.pem→ Path to your actual SSH key
# Test connection (does SSH work?)
ansible all -m ping
# Install Nginx on your EC2
ansible-playbook playbook.ymlDone! Visit http://YOUR_EC2_IP in your browser to see it working!
Your Mac Your EC2 Server
Ansible SSH (key)→ EC2 (Amazon Linux/Ubuntu)
Reads Installs
playbook Nginx
- Ansible reads
inventory.ymlto find your EC2 server - Connects via SSH using your key (no agent needed on EC2!)
- Runs tasks from
playbook.ymlone by one - Reports back what changed
Open ANSIBLE_GUIDE.md for:
- What is Ansible? (super simple explanation)
- Understanding confusing terms like
state: presentandbecome: yes - Complete file operations guide
- All important commands explained in depth
- Mac + EC2 specific setup instructions
- Troubleshooting guide
- 10 interesting Ansible facts
# Test connection
ansible all -m ping
# Run the playbook
ansible-playbook playbook.yml
# Test without actually doing anything (dry-run)
ansible-playbook playbook.yml --check
# See detailed output (for debugging)
ansible-playbook playbook.yml -v
# Check if your YAML syntax is correct
ansible-playbook playbook.yml --syntax-check
# Run only specific tasks (using tags)
ansible-playbook playbook.yml --tags "install"Can't connect to EC2?
- Test SSH manually first:
ssh -i ~/path/to/key.pem ubuntu@YOUR_EC2_IP - Check EC2 security group allows SSH (port 22) from your Mac's IP
- Verify key permissions:
chmod 400 ~/path/to/key.pem
Wrong user?
- Ubuntu AMI uses
ubuntuuser - Amazon Linux uses
ec2-useruser - Debian AMI uses
adminuser - Update
ansible_user:ininventory.ymlaccordingly
Can't see the website?
- Check AWS Security Group allows HTTP (port 80) from 0.0.0.0/0
- Make sure you're using the correct EC2 IP address
- Verify Nginx is running:
ansible all -m shell -a "systemctl status nginx"
Read the troubleshooting section in ANSIBLE_GUIDE.md for more help!
Once this works:
- Try modifying
playbook.ymlto install other software - Add more servers to
inventory.yml - Learn about variables and loops in the guide
- Explore roles for better organization
Start simple, grow as you learn!