HAProxy Configuration On AWS Using Ansible

🔰Task: Using Ansible Playbook, Configure Reverse Proxy i.e. Haproxy, and update its configuration file automatically each time a new Managed node (Configured With Apache Webserver) joins the inventory on AWS
Pre-requisites:
- AWS EC2 instances- At least two
- Installed Ansible on the control node
Step 1: Configure Ansible
Create a directory using the command: mkdir /etc/ansible

add the inventory file location in the ansible configuration file: ansible.cfg and write host_key_checking=False to disable the ssh key and provide privilege escalation.

Step 2: Create Inventory File
Add the ec2 instance IP address, username, private key, and connection type.

Step 3: Check the connectivity
Check the connectivity of the control node with managed nodes
Command: ansible all -m ping

Step 4: Create a Jinja file for haproxy.cfg
Create a jinja file for haproxy.cfg(.j2 extension) and write the following code in it.

Step 5: Write Code in the Playbook


Step 6: Run the playbook
To run the ansible-playbook use Command: ansible-playbook <file_name.yml>


Step 7: Check the load Balancers
Check the haproxy.cfg file.
Use Command: vim /etc/haproxy/haproxy.cfg

Haproxy successfully configured on load balancer node.
Now, Check whether the 8080 port is running or not
Use Command: netstat -tnlp


It’s working perfectly fine:)
😊Thank you for Reading😊