Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 10, 2022 02:10 am GMT

Ansible For Everyone(Practical) - Part 2

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

Image tweetImage cover

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.
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

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
  • Now lets update and install ANSIBLE

Run these commands

sudo apt-get updatesudo apt install software-properties-common -ysudo apt-add-repository ppa:ansible/ansiblesudo apt updatesudo apt install ansible -y 

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
  • Install Python
  sudo apt-get update  sudo apt-get install python3 -y

Configure SSH access

On Ansible Control Center

  • Genarate a rsa key.
cd .sshssh-keygen
  • 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

Note down this key

On Ansible Slaves

  • ssh into your slave server then,
cd .sshsudo nano authorized_keys
  • 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

Coming Soon .... Ansible play books

i would like to mention a blog from spacelift https://spacelift.io/blog/ansible-playbooks which i found very useful for those who wanna jump ahead and start experimenting ..

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


Original Link: https://dev.to/aws-builders/ansible-for-everyonepractical-part-2-58a5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To