Configuring HAproxy inside Docker using Ansible Automation

kanav Gupta
Mar 2, 2021

Task Description

Use Ansible playbook to Configure Reverse Proxy i.e. Haproxy and update it’s configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory.

In this task instead ,I am gonna use Docker container one container for configuring HAproxy and two containers for webservers

Ansible playbook to configure HAproxy and httpd

- hosts: lb
tasks:
- name: "installing Loadbalancer software"
package:
name: "haproxy"
- name: "copying haproxy configure file"
template:
dest: "/etc/haproxy/haproxy.cfg"
src: "/home/kanav/Desktop/haproxy.cfg.j2"
- command: "haproxy -f /etc/haproxy/haproxy.cfg"



- hosts: wb
tasks:
- name: "installing webserver software"
package:
name: "httpd"
- copy:
dest: "/var/www/html/index.html"
content: "welcome to my webserver"
- command: "/usr/sbin/httpd"

Ansible playbook executed successfully.Now let’s access website using haproxy ip with port number 5000

Let also access remaining two container ip’s

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response