DEV Community

Cover image for Ansible For Everyone(Practical) - Part 2
Anuvindh for AWS Community Builders

Posted on • Edited on

7 2

Ansible For Everyone(Practical) - Part 2

DAY 33- Ansible For Everyone(Practical) - Part 2 - Day Thirty Three

Image tweet

100 days of Cloud on GitHub - Read On iCTPro.co.nz - Read on Dev.to


📘 Please read Part one to understand bits and basics of ANSIBLE.


☁️ Lets setup the environment in AWS

  • We will spin up one EC2 as slave and one EC2 as the Master Node or the control center for ansible.
  • Then we use this Master node to connect the other EC2 instance (Slave).

🪛 Prerequsite

Image image

  • Access and privilages to launch EC2 with Ubuntu
  • Putty or any other SSH tools
  • Security group with ports ssh open (Port 22)

Setup environment

Lets launch 2 EC2 instances

  • Use AWS EC2 console or CLI. i am using two ubuntu instances here for this lab.
aws ec2 run-instances \
--image-id <ami-id> \
--instance-type <instance-type> \
--subnet-id <subnet-id> \
--security-group-ids <security-group-id>\
--key-name <ec2-key-pair-name> \
--count 2
Enter fullscreen mode Exit fullscreen mode

Set up Ansible Control Center

  • Rename one EC2 to Ansible Control Center on console

  • Now lets SSH into Ansible Control Center EC2

    • Rename the server
   sudo hostnamectl set-hostname Ansible-Control-Center
Enter fullscreen mode Exit fullscreen mode
  • Now lets update and install ANSIBLE

Run these commands

sudo apt-get update
sudo apt install software-properties-common -y
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible -y 
Enter fullscreen mode Exit fullscreen mode

Set up Ansible Slaves - Your ProdServer

  • Rename one EC2 to Ansible Slaves - Your ProdServer on console
  • Rename the server
   sudo hostnamectl set-hostname AnsibleSlaves-YourProdServer
Enter fullscreen mode Exit fullscreen mode
  • Install Python
  sudo apt-get update
  sudo apt-get install python3 -y
Enter fullscreen mode Exit fullscreen mode

Configure SSH access

On Ansible Control Center

  • Genarate a rsa key.
cd .ssh
ssh-keygen
Enter fullscreen mode Exit fullscreen mode
  • Press enter ,we donot require any changes.
    Image rsa key

  • Now if we ls we will be able to see id_rsa & id_rsa.pub, lets cat id_rsa.pub.

cat id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Note down this key

On Ansible Slaves

  • ssh into your slave server then,
cd .ssh
sudo nano authorized_keys
Enter fullscreen mode Exit fullscreen mode
  • Now on next line paste the key we previously noted & save it.

Now its play time.

Image its play time

Goto your Ansible Control Center EC2.

  • lets ssh into ansible slave, Image ssh

✅Connect with me on Twitter
🤝🏽Connect with me on Linkedin
🧑🏼‍🤝‍🧑🏻 Read more post on dev.to or iCTPro.co.nz
💻 Connect with me on GitHub


Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (1)

Collapse
 
anuvindhs profile image
Anuvindh • Edited

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post