Ansible Installation on AWS EC2 Server

Last Updated : 11 Aug, 2025

Automating server configuration and management in the cloud becomes far more efficient when you combine Ansible with AWS EC2. Ansible, a powerful open-source automation tool, allows you to manage multiple machines without the need for agents, while AWS EC2 provides scalable, on-demand virtual servers in the cloud.

In this guide, you will first learn about AWS EC2, and then follow a step-by-step process to install and configure Ansible on an AWS EC2 instance. By the end, you’ll be ready to automate tasks across your cloud infrastructure with ease.

AWS EC2

Amazon Elastic Compute Cloud (EC2) is a web service from Amazon Web Services (AWS) that lets you rent virtual servers called EC2 instances in the cloud. You can choose from various instance types based on your needs:

  • High computation tasks: Choose larger instance types such as t2.large or higher.
  • Low computation tasks: Opt for smaller instances such as t2.micro or t2.medium.

AWS EC2 allows you to scale resources up or down easily, making it suitable for a wide range of workloads.

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 Multiple 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 .
Comment
Article Tags:

Explore