Configuring HAproxy inside Docker using Ansible Automation
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

