Abhishek Kumar
Abhishek's almanac

Abhishek's almanac

How to Install and Configure ELK stack using Ansible playbook on AWS Ubuntu

Photo by Brooke Lark on Unsplash

How to Install and Configure ELK stack using Ansible playbook on AWS Ubuntu

Abhishek Kumar's photo
Abhishek Kumar
·Sep 29, 2022·

2 min read

Table of contents


  1. AWS account

Tight your grip on the handle as we start on this rollercoaster ride


Step 1. Create an EC2 instance

Create 2 EC2 instances (ansible-master and ansible-node) with t2.xlarge instance type.



Step 2. Setup ansible in ansible-master

Install ansible in ansible-master

To install and setup ansible in the Master node use the below commands(as root):

sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible

To check if successfully installed or not

ansible --version


To Generate SSH key



Copy the key generated for further use.

 cat /root/.ssh/id_rsa.pub


Step 3. Configuring ansible-node

In ansible-node type the following command:

cd .ssh

Open authorized_keys file using your vim code editor.

sudo vim authorized_keys

And paste the key generated in Step 2. and save the file.


Install net-tools package to IP address of ansible-node.

sudo apt install net tools

Now get the I.P. Address of the ansible-node using ifconfig


image.png The IP address of ansible-node is will be different)

In the ansible-master
Try establishing an SSH connection from the ansible-master using the below command:


(Note: Change with your ansible-node IP address.)


Type exit to exit from ssh connection.

Step 4. Establishing Connection between ansible-master and ansible-node.

In the ansible-master Edit the hosts file located in /etc/ansible/hosts

vim /etc/ansible/hosts

Add the following line in hosts file



Save and exit the file.

To test if the ansible-master is connected to ansible-node type the below command in ansible-master:

ansible -m ping all


Final Step. Running ansible-playbook


(Note: All the below commands are for ansible-master) Cloning the ansible playbook from GitHub.

git clone https://github.com/Abhishek-569/ansible-elk-playbook.git
cd  ansible-elk-playbook/
cd ansible-elk-playbook/

(Repetition is not a mistake) You can now see the content of main.yml and the roles folder in the current directory.


ansible-playbook  main.yml



Changing the in-Bound rules of security-group

To establish an HTTP connection with ElasticSearch (running at :9200 port) and Kibana(running at :5601 port) Change the inbound rules of the security group associated with ansible-node.


That is done now you can access the ElasticSearch at the public IP address of ansible-node with port 9200.(HTTP://{your_ansible-node_public_ip}:9200)

image.png And kibana at (HTTP://{your_ansible-node_public_ip}:5601)


----------------------------------------------The END---------------------------------------------------- image.png

Share this