Configuring HAProxy using Ansible Playbook

Introduction :

Ansible

Load Balancer

HAProxy

Task :

  - name: "Creating Directory"
file:
state: directory
path: /dvd

- name: "Mounting DVD"
mount:
path: /dvd
src: /dev/sr0
fstype: iso9660
opts: ro,noauto
state: mounted
ignore_errors: yes

- name: "Configuring YUM repo"
yum_repository:
name: AppStream
description: Repo for AppStream
file: dvd.repo
baseurl: file:///dvd/AppStream/
gpgcheck: no

- name: "Configuring Base YUM repo"
yum_repository:
name: BaseOS
description: Repo for BaseOS
file: dvd.repo
baseurl: file:///dvd/BaseOS/
gpgcheck: no

- name: "Installing haproxy"
package:
name: haproxy
state: present
vars_prompt:
- name: port_number
private: no
prompt: "Enter the port number for load balancer"
- name: "Copying haproxy configuration file"
template:
src: /ws5/haproxy.cfg.j2
dest: /etc/haproxy/haproxy.cfg
notify: Restarting haproxy
- name: "Stopping Firewall on port {{port_number}}"
firewalld:
port: "{{port_number}}/tcp"
zone: public
permanent: true
immediate: true
state: enabled


- name: "Making SElinux permissive"
selinux:
policy: targeted
state: permissive
- name: "Starting haproxy service"
service:
name: haproxy
state: started


handlers:
- name: Restarting haproxy
service:
name: haproxy
state: restarted

Configuring Backend Server with httpd :

tasks:
- name: "Creating Directory"
file:
state: directory
path: /dvd

- name: "Mounting DVD"
mount:
path: /dvd
src: /dev/sr0
fstype: iso9660
opts: ro,noauto
state: mounted
ignore_errors: yes

- name: "Configuring YUM repo"
yum_repository:
name: AppStream
description: Repo for AppStream
file: dvd.repo
baseurl: file:///dvd/AppStream/
gpgcheck: no

- name: "Configuring Base YUM repo"
yum_repository:
name: BaseOS
description: Repo for BaseOS
file: dvd.repo
baseurl: file:///dvd/BaseOS/
gpgcheck: no

- name: "Installing httpd software"
package:
name:
- httpd
- php
- name: "Copying web page"
template:
src: "/ws5/m.php"
dest: "/var/www/html/m.php"
<pre>
<?php
print "<br/>";
print `/usr/sbin/ifconfig`;
?>
</pre>
- name: "Stopping firewall"
firewalld:
port: "80/tcp"
zone: public
permanent: true
immediate: true
state: enabled

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