Open In App

How to install Ansible in AWS EC2 Server ?

Last Updated : 02 Jul, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
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 you will learn 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.

  • It uses playbooks to define tasks.
  • Tasks describe jobs such as installing Docker, installing Nginx, pulling Docker images, or updating systems.
  • Playbooks are written in YAML, a human-readable language.
  • Ansible can manage multiple machines at once. For example, updating 10 machines simultaneously without logging into each one manually.
  • Its agentless approach connects over SSH, reducing 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.

Now let's see the process of installing Ansible in AWS using EC2 server:

Install Ansible on AWS EC2 Instance: 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 [email protected]:/

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 .


Next Article
Article Tags :

Similar Reads