Hey guys hope you all are doing in today's article we are going to set haproxy using ansible so in future as many new controller node added in controller group they get entered in haproxy server. Let's get started with practical how-to implement this.
If you have not checked my previous article on ansible I recommend you to read that first in that we have talked about how to configure yum that is necessary for any practical and in that we have also covered how to automate docker using ansible.
Docker Automation using Ansible
So hey guys hope you all are doing today we are going to automate docker using ansible and launch our website using…
First, we have to set our inventory file for that we have made two groups controller and webserver so that when we run playbook we can specify the groups because we don't want our backend server to also install the haproxy server.Once the inventory is setup repeat the same steps to set up an ansible configuration file and checking connectivity.
Once All the steps are done make a new folder from the command:-
Inside that folder, we need to have one file called haproxy. cfg we need this because when we set up haproxy manually we go to /etc/haproxy/haproxy.cfg and enter our backend server IP so for this reason we have make clone of copy in our folder we will edit this file and send it to haproxy controller and then start the service.
Now lets setup playbook to configure haproxy server
Here we have use controller in host this mean all IP in controller groups will be set up as haproxy server yum module we have use to install haproxy software template module is used to copy Hadoop. cfg to target node service module is being used to start the service.
Now you might be thinking why we have used template we can use copy modules too for copying file to target Node well you are right we can use it but if only want to copy the file as it is then copied module is good but when target file has variables in it then template module is intelligent enough to detect them.
Will attach a GitHub link at the end for all files so you can clone and enjoy 😎
As you can see in the Hadoop. cfg file we have use for loop entering IP in configuration file this is template of jinja language
groups is pre-created variable in ansible having all ips from inventory to get specific group IP then you can use groups[‘group name’].
As you can see in the above image haproxy is not configured on the controller node.
As soon as we run our playbook haproxy get configured.
Guys, here we come to the end of this blog I hope you all like it and found it informative. If have any query feel free to reach me :)
Guys follow me for such amazing blogs and if have any review then please let me know I will keep those points in my mind next time while writing blogs. If want to read more such blog to know more about me here is my website link https://sites.google.com/view/adityvgupta/home.Guys Please do not hesitate to keep 👏👏👏👏👏 for it (An Open Secret: You can clap up to 50 times for a post, and the best part is, it wouldn’t cost you anything), also feel free to share it across. This really means a lot to me.