✍ DEPLOY HAPROXY LOADBALANCER AND WEBSERVER ON THE AWS CLOUD USING ANSIBLE DYNAMIC INVENTORY CONCEPT :

HELLO EVERYONE✌✌,

✍TASK DESCRIPTION :

✍WHAT IS THE USE OF ROLES IN ANSIBLE ?

✍WHAT IS AN ANSIBLE GALAXY ROLES ?

✍WHAT IS LOAD BALANCER ?

✍PREREQUISITE :

👉STEP : 1

# vim ip.txt[loadbalancer] 13.233.206.110 [Webserver] 3.7.69.24
13.235.79.168

👉STEP: 2

# vim /etc/ansible/ansible.cfg
# cat /etc/ansible/ansible.cfg
[defaults]
inventory = /root/ip.txt
host_key_checking = False
roles_path = /root/ansible_roles
private_key_file = /root/aws_ansible.pem
remote_user = ec2-user
ask_pass = false


[privilege_escalation]
become = true
become_user = root
become_method = sudo
become_ask_pass = false

👉STEP : 3

# ansible-galaxy  init  webserver   ---> role created for Webserver
# ansible-galaxy init loadbalancer
---> role created for LoadBalancer

👉NEXT :

👉NEXT :

👉STEP : 4

# vim main.yml- name: TO INSTALLING THE HTTPD INSTALLING HTTPD  
package:
name: httpd
state: present
- name: TO INSTALLING THE PHP SOFTWARE
package:
name: php
state: present
- name: TO COPY INDEX.PHP TO THE HTTPD DOCUMENT ROOT
tempalte:
src: index.php
dest: /var/www/html/index.php
- name: TO STARTING THE HTTPD SERVICES service:
name: httpd
state: started

👉STEP : 5

# vim index.php<pre>
<?php
print `/usr/sbin/ifconfig`;
?>
</pre>

👉STEP : 6

# vim main.yml# tasks file for loadbalancer  - name: TO INSTALL THE HAPROXY  
package:
name: haproxy
state: present
- name: TO CONFIGURE THE HAPROXY BY COPYING HAPROXY.CFG FILE
template:
src: haproxy.cfg.j2
dest: /etc/haproxy/haproxy.cfg
notify:
- restart_haproxy
service:
name: haproxy
state: started

👉STEP : 7

# vim main.yml# handlers file for loadbalancer- name: TO RESTARTING THE HAPROXY SERVICES
service:
name: haproxy
state: restarted

👉STEP : 8

#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# https://www.haproxy.org/download/1.8/doc/configuration.txt
#
#---------------------------------------------------------------------


#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2


chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon


# turn on stats unix socket
stats socket /var/lib/haproxy/stats


# utilize system-wide crypto-policies
ssl-default-bind-ciphers PROFILE=SYSTEM
ssl-default-server-ciphers PROFILE=SYSTEM


#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000


#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
bind *:8080
acl url_static path_beg -i /static /images /javascript /styleshe ets
acl url_static path_end -i .jpg .gif .png .css .js


use_backend static if url_static
default_backend app


#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check


#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin

{% for i in group['webserver'] %}
server app {{loop.index }} {{ i }}:80 check
{% endfor %}

👉STEP : 9

# vim task15.yml- hosts: Webserver  
roles:
- webserver
- hosts: loadbalancer
roles:
- loadbalancer

👉STEP : 10

# ansible-playbook task15.yml

👉STEP : 11

SEE YOU IN THE NEXT BLOG WITH MORE AMAZING TASKS.

THANK YOU🙏🙏 GUYS FOR READING MY BLOG…

SIGNING OF FORM MY SIDE 👋👋

KEEP LEARNING🙇‍♂️📖🙇….

KEEP SHARING✌✌….

--

--

ARTH-LEARNER || IIEC RISE || FLUTTER || PYTHON || REDHAT || DOCKERS || AI || BIG DATA || HADOOP || ANSIBLE || KUBERNETES || ML || DL || JENKINS || OPENSHIFT ||

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Priya Soni

ARTH-LEARNER || IIEC RISE || FLUTTER || PYTHON || REDHAT || DOCKERS || AI || BIG DATA || HADOOP || ANSIBLE || KUBERNETES || ML || DL || JENKINS || OPENSHIFT ||