Skip to content
PrinceSah09Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Simple Ansible Setup for Beginners (Mac + EC2)

Learn Ansible by doing! This is a minimal setup for managing your EC2 instance from your Mac.

What's in Here

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

Quick Start (3 Simple Steps)

Step 1: Install Ansible on Your Mac

pip3 install ansible

# Check it worked
ansible --version

Step 2: Add Your EC2 Details

Edit inventory.yml and change these:

  • YOUR_EC2_IP → Your actual EC2 public IP (like 54.123.45.67)
  • ~/Downloads/my-key.pem → Path to your actual SSH key

Step 3: Run It!

# Test connection (does SSH work?)
ansible all -m ping

# Install Nginx on your EC2
ansible-playbook playbook.yml

Done! Visit http://YOUR_EC2_IP in your browser to see it working!

What Just Happened?

Your Mac                          Your EC2 Server
                  
                                             
  Ansible    SSH (key)→   EC2 (Amazon Linux/Ubuntu)     
                                             
  Reads                          Installs    
  playbook                       Nginx       
                                             
                  
  1. Ansible reads inventory.yml to find your EC2 server
  2. Connects via SSH using your key (no agent needed on EC2!)
  3. Runs tasks from playbook.yml one by one
  4. Reports back what changed

Learn More

Open ANSIBLE_GUIDE.md for:

  • What is Ansible? (super simple explanation)
  • Understanding confusing terms like state: present and become: yes
  • Complete file operations guide
  • All important commands explained in depth
  • Mac + EC2 specific setup instructions
  • Troubleshooting guide
  • 10 interesting Ansible facts

Useful Commands

# 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"

Not Working?

Can't connect to EC2?

  1. Test SSH manually first: ssh -i ~/path/to/key.pem ubuntu@YOUR_EC2_IP
  2. Check EC2 security group allows SSH (port 22) from your Mac's IP
  3. Verify key permissions: chmod 400 ~/path/to/key.pem

Wrong user?

  • Ubuntu AMI uses ubuntu user
  • Amazon Linux uses ec2-user user
  • Debian AMI uses admin user
  • Update ansible_user: in inventory.yml accordingly

Can't see the website?

  1. Check AWS Security Group allows HTTP (port 80) from 0.0.0.0/0
  2. Make sure you're using the correct EC2 IP address
  3. Verify Nginx is running: ansible all -m shell -a "systemctl status nginx"

Read the troubleshooting section in ANSIBLE_GUIDE.md for more help!

Next Steps

Once this works:

  1. Try modifying playbook.yml to install other software
  2. Add more servers to inventory.yml
  3. Learn about variables and loops in the guide
  4. Explore roles for better organization

Start simple, grow as you learn!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages