Create an Ansible Roles for Webserver and Haproxy…
🔅Create an ansible role myapache to configure Httpd WebServer.
🔅Create another ansible role myloadbalancer to configure HAProxy LB.
🔅We need to combine both of these roles controlling webserver versions and solving challenge for host ip’s addition dynamically over each Managed Node in HAProxy.cfg file.
♦Inventory File :
[webserver]
192.168.1.108 ansible_user=root ansible_ssh_pass=password ansible_connection=ssh
192.168.1.106 ansible_user=root ansible_ssh_pass=password ansible_connection=ssh[loadbalancer]
192.168.1.107 ansible_user=root ansible_ssh_pass=password ansible_connection=ssh
♦️ Ansible Configuration File :
🔅 Create an ansible role “httpd” to configure httpd WebServer.
ansible-galaxy role init httpd
Create another ansible role “haproxy” to configure HAProxy LB.
ansible-galaxy role init haproxy
♦️ Here, we can see two roles created using command :
ansible-galaxy role list --roles-path /root/roles

Now start writing roles :
♦️ In httpd role,
- In tasks ;

2. In vars ;

3. In handlers ;

4. In files ;

♦️ In haproxy role,
- In tasks ;

2. In vars ;

3. In handlers ;

4. In templates ;


♦️ Now run the playbook ,

♦️ In Haproxy Configuration File we can see that ip’s are added dynamically over managed nodes ;

♦️ Now we have to check on browser :

If we can see while we relod our web page then ip get automatically changed then our task is successful. Let’s check

Here we go our ip changed dynamically …….