Video Tutorial:-


Ansible PlayBook:-

- hosts: web

  tasks:

    - name: Installing httpd

      package:

        name: httpd

        state: present

    - name: Installing php

      package:

        name: php

        state: present

    - name: Copying web page

      template:

        src: web.php                    ( Create Your Webpage in current directory )

        dest: /var/www/html

    - name: Starting httpd service

      service:

        name: httpd

        state: restarted

- hosts: lb

  tasks:

    - name: Installing haproxy

      package:

        name: haproxy

        state: present

    - name: Configuring haproxy

      template:

        src: haproxy.cfg.j2

        dest: /etc/haproxy/haproxy.cfg

    - name: Starting haproxy

      service:

        name: haproxy

        state: restarted

    - name: Allow Firewall port https

      firewalld:

        port: 80/tcp

        state: enabled

        permanent: yes

        immediate: yes

    In haproxy.cfg file (Write this in round robin balancing between the various backends)

{% for i in groups['web'] %}

    server  app{{ loop.index }} {{ i }}:80 check

{% endfor %}

    Inventory File

[lb]

192.168.1.108 ansible_user=root ansible_ssh_pass=redhat  ansible_connection=ssh

[web]

192.168.1.107 ansible_user=root ansible_ssh_pass=redhat  ansible_connection=ssh

192.168.1.106 ansible_user=root ansible_ssh_pass=redhat  ansible_connection=ssh