▓█►卂n𝓈ι乃ℓ𝑒 ⓡ𝓸𝓁𝕖ร ◄█▓

Welcome back to my another article😊

♦️Ansible :

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management (allowing remote PowerShell execution) to do its tasks.

Hopefully, now you have a little bit of idea about above mentioned So let’s see what are the pre-requisites and how you can design the below-mentioned architecture using ansible.

♦️Ansible Architecture :

Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.

Being designed for multi-tier deployments since day one, Ansible models your IT infrastructure by describing how all of your systems inter-relate, rather than just managing one system at a time.

It uses no agents and no additional custom security infrastructure, so it’s easy to deploy — and most importantly, it uses a very simple language (YAML, in the form of Ansible Playbooks) that allow you to describe your automation jobs in a way that approaches plain English.

♦️Modules :

Ansible works by connecting to your nodes and pushing out scripts called “Ansible modules” to them. Most modules accept parameters that describe the desired state of the system. Modules gives intelligence .Ansible then executes these modules (over SSH by default), and removes them when finished. Your library of modules can reside on any machine, and there are no servers, daemons, or databases required.

You may write specialized modules in any language that can return JSON (Ruby, Python, bash, and so on).

♦️Inventory :

By default, Ansible represents the machines it manages in a file (INI, YAML, and so on) that puts all of your managed machines in groups of your own choosing.

To add new machines, there is no additional SSL signing server involved, so there’s never any hassle deciding why a particular machine didn’t get linked up due to obscure NTP or DNS issues.

If there’s another source of truth in your infrastructure, Ansible can also connect to that. Ansible can draw inventory, group, and variable information from sources like EC2, Rackspace, OpenStack, and more.

---
[webservers]
www1.example.com
www2.example.com

[dbservers]
db0.example.com
db1.example.com

Once inventory hosts are listed, variables can be assigned to them in simple text files (in a subdirectory called ‘group_vars/’ or ‘host_vars/’ or directly in the inventory file.

♦️Ansible Playbooks :

Ordered lists of tasks, saved so you can run those tasks in that order repeatedly. Playbooks can include variables as well as tasks. Playbooks are written in YAML and are easy to read, write, share and understand.

Here’s what a simple playbook looks like:

---
- hosts: webservers
serial: 5 # update 5 machines at a time
roles:
- common
- webapp

- hosts: content_servers
roles:
- common
- content

♦️Control Node :

Any machine with Ansible installed is known as controller node. You can run Ansible commands and playbooks by invoking the or command from any control node. You can use any computer that has a Python installation as a control node - laptops, shared desktops, and servers can all run Ansible. However, you cannot use a Windows machine as a control node. You can have multiple control nodes.

♦️Managed Node :

The network devices (and/or servers) you manage with Ansible. Managed nodes are also sometimes called “hosts”. Ansible is not installed on managed nodes.

♦️Load Balancer :

load balancer acts as the “traffic cop” sitting in front of your servers and routing client requests across all servers capable of fulfilling those requests in a manner that maximizes speed and capacity utilization and ensures that no one server is overworked, which could degrade performance. If a single server goes down, the load balancer redirects traffic to the remaining online servers. When a new server is added to the server group, the load balancer automatically starts to send requests to it.

In this manner, a load balancer performs the following functions:

  • Distributes client requests or network load efficiently across multiple servers
  • Ensures high availability and reliability by sending requests only to servers that are online
  • Provides the flexibility to add or subtract servers as demand dictates

♦️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.

♦️Ansible Roles :

Roles let you automatically load related vars_files, tasks, handlers, and other Ansible artifacts based on a known file structure. Once you group your content in roles, you can easily reuse them and share them with other users.

So let’s begin to enjoy our today’s task….🤩🤩

🔰Task Description📄

🔅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,

  1. In tasks ;

2. In vars ;

3. In handlers ;

4. In files ;

♦️ In haproxy role,

  1. In tasks ;

2. In vars ;

3. In handlers ;

4. In templates ;

🔅 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.

♦️ In main playbook setup.yml ,

♦️ 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 …….

♦️ GitHub URL :

Our Task is completed successfully !!!!🤩🙌

Thanks for Reading ❗❗

🔰Keep Learning ❗❗🔰Keep Sharing ❗❗

Arth Learner — LinuxWorld Informatics Pvt Ltd