Today we going to create two Ansible roles first is for configuring Httpd WebServer and the second is for configuring HAProxy LB. by these two roles we solving challenges for host ip’s addition dynamically over each Managed Node in HAProxy.cfg file.
for this first, we create a role named myapache using the command “ansible-galaxy init myapache” and then we create another role named myloadbalancer
then in myapache/tasks/main.yml file we write this code
in myapache/files/ folder we create a index.php file.
then in the myloadbalancer/tasks/main.yml file, we write this code
in myloadbalancer/templates folder we past “haproxy.cfg.j2” file with some modification. here at the end of file, we change
create a file setup.yml in this file we write this code
then we run this playbook using the command “ansible-playbook setup.yml” output is