Ansible Dynamic Inventory + AWS EC2

In this story, I am going to illustrate “Configuration management using Ansible Dynamic Inventory” in AWS EC2 instances.

What is Ansible Dynamic Inventory and what is the need for dynamic inventory?
There are two types of Inventories in Ansible.
1. Static Inventory
2. Dynamic Inventory

Static Inventory: In this inventory file where you define hostname, host ip’s, host variables of the slave's machines for the configuration management.

In real-time, there will be hundreds of machines where you need to do configuration management. So you cannot write those hostnames and host ip’s manually in the static inventory file. …


1. Launch an Amazon EC2 Linux instance.
2. Open the default port 8080 in the inbound rules of your instance security group.


Step 1: Create a jenkins-installation script file and give executable permissions to the file.

$ sudo vi

$ sudo chmod u+x

Step 2: Add the below commands in the script file.

#!/bin/bash# Step 1
echo "Installing the Oracle Java JDK as a prerequisite for jenkins set-up"
sudo wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" rpm -ivh jdk-8u131-linux-x64.rpm# Step 2
echo "Downloading Jenkins Repo"
sudo wget -O /etc/yum.repos.d/jenkins.repo
# Step 3
echo "Importing repo key"

Vara Prasad Palla

Senior DevOps and AWS Engineer. I am an AWS Certified Solution Architect Professional.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store