HAproxy + AWS + Ansible

Deploy Load Balancer on AWS through ANSIBLE!

What is Load Balancing?

So, Let’s Get started…

pip3 install boto
1-Loadbalancer and 2-Webserver ---> Managed Nodes(MN)
Run the Playbook → ansible-playbook instance.yml
 wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini
chmod +x ec2.py
chmod +x ec2.ini
#!/usr/bin/python3
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=XXXXXXXXX
ansible-galaxy init loadbalancer  ---> role created for loadbalancer 
ansible-galaxy init webserver ---> role created for webserver
roles_path=/Ansible_Task_3
- name: INSTALL HAPROXY SERVER
package:
name: haproxy
state: present
- name: COPY HAPROXY CONF FILE TO LB
template:
dest: “/etc/haproxy/haproxy.cfg”
src: “haproxy.cfg.j2”
notify: LBrestart
- name: START THE SERVICE
service:
name: haproxy
state: started
- name: LBrestart
service:
name: haproxy
state: restarted
yum install haproxy -y      ---->  It will install haproxy
backend app
balance roundrobin
{% for i in groups[‘tag_Name_web’] %}
server app{{ loop.index }} {{ i }}:80 check
{% endfor %}
- name: INSTALL HTTPD PACKAGE
package:
name: httpd
state: present
- name: COPY THE FILE
template:
dest: "/var/www/html/"
src: "index.html"
notify: restart
- name: START THE SERVICE
service:
name: httpd
state: started
- hosts: tag_Name_LoadBalancer
roles:
- role: loadbalancer
- hosts: tag_Name_web
roles:
- role: webserver
ansible-playbook setup.yml
13.127.23.104:8080      ---> This is for my case

Finally, Our LoadBalancer has been deployed successfully.🤘

Thank You For Reading!😇

Started Learning New Technologies