Open In App

How to install Ansible in AWS EC2 Server ?

Last Updated : 30 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Ansible is an automation tool which helps in managing the configuration over multiple machines . On the other hand AWS EC2 is a web service which allows users to rent any required virtual server . Here in this guide, we will first discuss what is Ansible. Then we will discuss AWS EC2 Service. After this, we will walk you through the different steps to install and configure Ansible on an AWS EC2 server.

What is Ansible ?

Ansible is an open source automation tool which helps in configuration management and application deployment . Ansible uses SSH to connect with the other hosts for running tasks. Ansible uses playbook to write the tasks . Tasks are basically the description of a job. For example installation of docker , installation of nginx , pulling docker image or may be update system , etc . Playbooks are written using the human readable programming language, YAML. Ansible helps to maintain multiple machine at a time . Lets say there are 10 machines which needs system update . The system update can be performed through Ansible without any manual installation on each machine . This agentless approach reduces the manual overhead . In summary we can say Ansible is a powerful open source automation tool which is used by organizations to manage configuration remotely over multiple machines which results in improving the efficiency and reducing the manual overhead .

What is AWS EC2 ?

EC2 also known as Elastic Cloud Compute (EC2), which is an AWS web service that allows user to rent virtual server on an AWS cloud platform . These virtual servers are called EC2 Instances . There are different types of EC2 instances which users can select on their requirement. For example if an user is doing any high computation task , they can choose t2.large or any higher EC2 instance type or if they are doing any low computation task they can choose t2.micro or t2.medium. EC2 service also provides variety of operating system images such as Ubuntu, CentOS , Amazon Linux, Windows and many more. EC2 instances can also be scaled up or down on the basis of traffic it receives by using a load balancer. In summary we can say EC2 provides flexible, scalable and cost effective solutions to organizations to run their application on AWS cloud platform .

How to Install Ansible On AWS EC2 Instance? A Step-By-Step Guide

Step 1 : Create an EC2 instance with ubuntu as operating system .

Launch EC2 Instance

Step 2 : Then connect your EC2 instance and update with the command below .

sudo apt update

Updating The Software

Step 3 : Install ansible by using the commands below .

sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install ansible

Installation of Ansible

Step 4 : Verify whether ansible is installed or not .

ansible --version

Verify ansible installation

Configure Ansible On Different Machines

Step 1 : Create a master node . Here open SSH port and also use a master key .

Step 2 : Create a worker node . Here open SSH and HTTP port , and also use a worker key.

Step 3 : Connect master node using SSH and install ansible on this .

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install ansible

Installing Ansible

Step 4 : Now copy the private key of worker node into the master node . Here use the command below to copy the private key into the home directory .

scp -i "Ansible-master.pem" Ansible-worker.pem ubuntu@ec2-54-146-224-195.compute-1.amazonaws.com:/

Copying Ansible Pem File

Step 5 : Now make some changes in the ansible configuration file . Here assign host_key_checking to False .

sudo su
ansible-config init --disabled -t all > ansible.cfg
vi ansible.cfg

Configuring Inventory

Step 6 : Grant the read permission to the private key of worker node that is present inside the master node .

chmod 400 Ansible-worker.pem

Restricting Permission of Pem File

  • Now you have successfully configured Ansible on a worker machine . You can now write custom playbooks to automate the tasks on the worker node .

Conclusion

Here in this article you have first learned what is Ansible . Then you have learned about EC2 Service provided by AWS . After this you have created a EC2 instance in free tier with Ubuntu as operating system . Then you have followed the steps to install Ansible on the EC2 Instance . After this you have created a master node and worker node , configured Ansible to automate the tasks .

How To Install Ansible In AWS EC2 Server ? – FAQ’s

What is the Primary Use of Ansible ?

Primary use of Ansible is to automate the IT tasks like configuration management and application deployment .

What is the difference between Ansible and Terraform ?

Ansible is primarily used for managing the configuration of multiple machines but Terraform primary use is in provisioning and managing infrastructure on various cloud platforms .

What is Ansible playbooks ?

Ansible playbooks are YAML files which consists of a set of tasks and configuration to be run at the different machines .

What are the tasks in Ansible ?

Task are the individual units of work which are defined in the Ansible playbooks .

What is the purpose of Ansible roles ?

Ansible roles provide a way to organize and reuse tasks which makes easier management of complex configurations in Ansible .



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads