Day 55: Understanding Configuration Management with Ansible  (Jan 20, 2024)

Day 55: Understanding Configuration Management with Ansible (Jan 20, 2024)

🙏 Introduction:

In this blog, we'll explore Ansible, an open-source automation tool that's important for managing configurations, deploying apps, organizing intra-service tasks, and helping with provisioning.

🔶What's this Ansible?

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.

🎯Task: 1

  1. Installation of Ansible on AWS EC2 (Master Node)

  • Create an EC2 instance

  • Add the Ansible PPA repository using the following command
sudo apt-add-repository ppa:ansible/ansible

  • Now update the Package manager
sudo apt update

  • Install Ansible using the following command
sudo apt install ansible

  • To check the version of Ansible using the following command
ansible --version

🎯Task: 2

  1. Read more about Hosts file sudo nano /etc/ansible/hosts ansible-inventory --list -y

Ansible hosts file is a configuration file that contains a list of hosts or servers that Ansible can manage. The hosts file is located at /etc/ansible/hosts on the Ansible control node, and it is used to define the inventory of hosts that Ansible can manage.

To edit the hosts file

sudo vim /etc/ansible/hosts

Once the file is open, you can add the IP addresses or hostnames of the servers you want to manage. The format for adding hosts is as follows

web1 ansible_host=
web2 ansible_host=

db1 ansible_host=
db2 ansible_host=

In this example, we have two groups: web_servers and database_servers, each containing two hosts. You can define various attributes for each host, such as ansible_host (IP address or hostname) and others.

After adding the hosts to the file, you can verify the inventory of hosts that Ansible can manage using the ansible-inventory command.

ansible-inventory --list -y

This command displays a YAML-formatted list of hosts and their attributes, including hostnames, IP addresses, and any other defined variables or group memberships

🎯Task: 3

  1. Setup 2 more EC2 instances with same Private keys as the previous instance (Node)

  • Launch 2 new EC2 instances with same private keys as Ansible-master-node instance

  1. Copy the private key to master server where Ansible is setup

  • Create a directory on the master node named as keys and get the path of the keys directory

  • From our local machine, transfer the private key to the master node..
scp -i "ansible-key.pem" ansible-key.pem

  1. Try a ping command using ansible to the Nodes

  • Configure the host file on master machine
sudo vim /etc/ansible/hosts
  • Add our slave’s Ip address here
host_1 ansible_host= 
host_2 ansible_host=


  • To verify the inventory of hosts
ansible-inventory --list

  • Change the private key permission

  • To check the nodes are connected
ansible -m ping all