Load-balancer using ansible!

What is ansible?

Ansible is an open source IT configuration management (CM) and automation platform, provided by Red Hat. It uses human-readable YAML templates so that users can program repetitive tasks to occur automatically, without learning an advanced language.

Ansible replaces ad hoc scripting or manual CM with an automated and repeatable process. The tool pushes application code, programs and IT infrastructure setup instructions via modules to managed nodes, whether physical servers, virtual machines (VMs) or cloud instances. The tool also gives users the option to invert its setup to a pull architecture, where managed nodes request instructions from the tool, typically done to enable scaling.

What is HAproxy ?

HAProxy, which stands for High Availability Proxy, is a popular open source software TCP/HTTP Load Balancer and proxying solution which can be run on Linux, Solaris, and FreeBSD. Its most common use is to improve the performance and reliability of a server environment by distributing the workload across multiple servers (e.g. web, application, database). It is used in many high-profile environments, including: GitHub, Imgur, Instagram, and Twitter.

In this guide, we will provide a general overview of what HAProxy is, basic load-balancing terminology, and examples of how it might be used to improve the performance and reliability of your own server environment.

Let’s start the procedure!

1 I have created a PHP code that will show your machine’s IP.

You can see the code above.

  • These are the IP group created for ansible one will act as a load balancer and server.
  • Then you should check the connectivity.

ansible all -m ping!

  • Create a workspace where you will paste the HAproxy configuration and will write the code.

Check the configuration file of HAproxy and make some changes in it

  • Now write the playbook
  • Now lets see if the playbook is working!

As you can clearly see the playbook is properly working.

* Now lets see if it is practically working!

As you can see the IP in the URL is and the IP in the screen in hence the playbook is working fine!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store