Ansible Playbook To Configure Reverse Proxy

Description:

Ansible:

Ansible playbooks:

HAProxy:

Steps to Follow:

Create an ansible configuration file to connect AWS

[defaults]
inventory = inventory_path
host_key_checking=False
command_warning = False
private_key_file = aws_key
remote_user = ec2-user
roles_path: roles_path[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False

Update Inventory

192.168.43.70   ansible_user=root   ansible_ssh_pass=123   ansible_connection=ssh
# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm# yum install sshpass

Create a Haproxy Configuration File

Installing Haproxy server

bind *: port
{% for i in groups['group_name'] %}
server app{{loop.index}} {{i}}:port check
{% endfor %}

Create a PHP webpage

Create an Ansible Playbook

- hosts: httpd
tasks:
# apache web server
- name: "install httpd package"
package:
name: "httpd"
state: present
- name: "install php package"
package:
name: "php"
state: present
- name: "copy web pages to the server"
copy:
src: "/var/www/html/index.php"
dest: /var/www/html/
notify: restart httpd
- name: "start httpd service"
service:
name: "httpd"
state: "started"
handlers:
- name: "restart httpd"
service:
name: "httpd"
state: "restarted"
# loadbalancer
- hosts: lb
tasks:
- name: "installing HAProxy"
package:
name: "haproxy"
state: present
- name: "copy haproxy configuration file"
template:
src: "haproxy.cfg"
dest: "/etc/haproxy/"
notify: lb restart
- name: "start HAproxy service"
service:
name: "haproxy"
state: started
handlers:
- name: "lb restart"
service:
name: "haproxy"
state: restarted

Thanks, for reading…

Keep Learning Keep Sharing !!!