Updated: Aug 14, 2020
In the last articles we have studied a lot about ansible and are well aware that ansible’s functionality is very much dependent on inventory file.
Ansible inventory is a file that contains the list of all servers on which ansible will perform tasks.
In the previous examples we have been creating this file manually.
This approach is fine for small environments but today’s IT infrastructure demands flexibility, scalability, and everyday companies are moving towards setting up their infrastructure on cloud.
Most important feature of cloud computing is auto scaling that means servers can terminate and new servers can be launched depending upon the load on the application. Now in this scenario, it is very hard to keep track of the servers and do manual management of ansible inventory file.
Here the concept of dynamic inventory comes to the rescue 😊
Major cloud providers provide custom scripts that can automatically detect the running servers and populate the inventory file. Here we are going to use AWS cloud platform to demonstrate the concept of dynamic inventory.
We will proceed step by step to create our lab environment for Ansible on AWS.
Create free tier account on AWS by signing by clicking here.
On the AWS console go to
Services -- EC2 -- Launch 3 EC2 instances like below
Select the instance type as Amazon Linux
Select t2.micro as instance type.
Only make the number of instances as 3 ( as we want to launch 3 servers) and leave the other settings as it is .
Attach a security group to the instance which allows port 22 and 80 like below
Now either select the existing pem key or create a new key pair. Then click on Launch Instance and wait for some time. 3 instances will come up.
Name the three instances as ansible1,ansible2 and ansible3 (name can be anything you like)
Here ansible1 will be the ansible master node and ansible2 and ansible3 will be the ones on which ansible will execute commands.
So we are done with the initial setup on AWS. In the next article we will move forward with it.
Image credits : devopscube.com