How to install Ansible in AWS EC2 Server ?
Last Updated :
02 Jul, 2025
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 .

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

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

Step 4 : Verify whether ansible is installed or not .
ansible --version

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

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]:/

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

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

- 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 .
Similar Reads
How to Install R on AWS EC2? R is widely used as a different programming language. There are several programming languages are present for different purposes. The C programming language is used to get basic knowledge in the programming field. Java programming language is used to get some deep knowledge of programming & its
7 min read
How to Install Go on AWS EC2? EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual computer on which we can perform all our tasks and we have the authority to configure, launch or even dissipate this virtual computer.Go is an open-source,
2 min read
How To Create Redhat EC2 Instance in AWS provisioning the Red Hat Enterprise Linux (RHEL) instances on Amazon Web Services (AWS) offers a powerful and versatile solution for hosting and running applications, overseeing the jobs, and utilizing the abilities of both platforms. Red Hat Enterprise Linux is a main Linux distribution eminent for
5 min read
How to Install MySQL on AWS EC2? AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
2 min read
How to Install PHP on AWS EC2? AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
2 min read