How to install ansible on AWS-setup ansible lab in aws with ec2 instances

0 Comment

How to install ansible on AWS ec2 instances

to install ansible on Amazon Linux or to setup ansible lab in aws we need two or three ec2 instances. one is ansible master ec2 instance remaining ec2 instances are clients. in the master ec2 instance only we will install ansible.

Launch three or two  ubuntu 16.04 instances

give Name one ubuntu ec2 instances as ansible-master

give remaining ec2 instances names as client1, clinet2

in both ansible master and clients  security groups

open ssh port no  22 from anywhere

How to setup ansible practice lab in aws ec2 instances

ansible built on python so install python in all machines

install python in ansible master and clients instances

ansible and its modules are built on python, so we have to install python in all master and client machines.

to install python execute below commands as root user

check python version with

installing ansible in ansible master instance

run below commands as root user

check ansible with

establish ssh connection between ansible master and clients

to establish a connection between master and clients we have to generate the id_rsa.pub key in master and paste this key in authorized_keys file of client machines. This file exists in the .ssh directory. So if the .ssh directory has not existed in client ec2 instances, We have to create the .ssh directory and inside that, we have to create the authorized_keys file.

generating id_rsa.pub  public key in ansible master instance

in master, ec2 instance execute below commands

setup ansible lab in aws ec2 instanaces

It will create the id_rsa.pub key in the .ssh directory

setup ansible in aws

Copy this id_rsa.pub key

In All Client Ec2 Instances

Sudo -i

cd .ssh

ls

Here you can see the authorized_keys file.   [If the file is not existed here create the file with touch command

touch authorized_keys  and paste the id_rsa.pub key in this file

Vi  authorized_keys

configure ansible in aws ec2

Paste id_rsa.pub  key of the master here

setup ansible in aws ec2now we have shared ssh keys between master and clients

Adding clients to ansible master

to add clients to ansible master machine, we need to add all IP’s of clients in master machine /etc/ansible/hosts file

now go to ansible master machine

Ansible AWS Inventory

cd /etc/ansible

vi hosts

add like below

[web]

10.0.0.14

install ansible in aws ec2 instance

here 10.0.0.14 is private IP of the client1 machine

here you can mention all client machines private IP’s

configure ansible in aws

the first time it will ask are you sure you want to continue connecting yes/no

write yes and click on enter

you can see the output in green color.

now we have successfully configured ansible practice lab in aws.

now you can run your playbooks and roles in clients.

IMP POINTS

  • allow ssh port forwarding between clients and master by opening port no 22
  • install python in all master and client ec2 instances
  • install ansible in master ec2 instance
  • generate the public key in ansible master instance
  • copy id_rsa.pub key and paste in all clients instances authorized_keys  file
  • enter all client IPs in master /etc/ansible/hosts   file
  • now you can run your playbooks

 

 

 

  • install ansible in aws ec2 instances
  • ansible aws
  • aws ansible
  • install ansible on Amazon Linux
  • ansible aws example
  • ansible connect to the ec2 instance
  • how to install ansible on aws ec2 instance

 

 

[top]

Leave a Reply

Your email address will not be published. Required fields are marked *