fabiochiu/medium-articles huggingface dataset:
Using Ansible to set up a Load Balancer & Webservers with dynamic binding!
By: Harshit Dawar
Tags: DevOps, Load Balancing, Ansible, Apache, Automation

In this rapid world, DevOps is a very important technology. It is one of the most demanding technologies in the present, therefore understanding it conceptually is a very important factor today for anyone.

I used “understanding” in the above paragraph because learning is not required, & also learning is not for long term goal, understanding is for the long term goal. So, everyone should focus on understanding the concepts instead of learning them.

In this blog, a complete practical will be covered which includes setting up the load balancer or reverse proxy using HAProxy software, Webserver using the Apache Webserver software, & using Ansible to automate everything. In addition to that, Web servers will be attached/bound to the load balancer dynamically, instead of making their entry in the configuration file of the Load Balancer.

Note: If you are not comfortable or if you do not know anything about Ansible, I would suggest to please go through my below-mentioned blog. It covers Ansible in brief, & that much knowledge is sufficient to proceed. But, if you have good knowlegde about Ansible that it will be very easy for you to proceed. Otherwise, even if you didn’t understand the internal working, you can use the code to fulfill the need.

Brief about HAProxy!

It is software that is used for Load Balancing i.e. it has the capability to redirect the requests of the client to one out of the multiple machines bound to it, & this redirection is possible by using the concept of the reverse proxy.

Load Balancing is very much important because when the online business grows, then only a single machine cannot handle a huge amount of requests, therefore multiple machines are used.

The reason for using an extra machine as a load balancer is to provide only 1 single website to the customers, instead of providing multiple IP Addresses of the multiple web servers to the customers which will highly degrade the business reputation.

Now, that being said, let’s proceed towards the main project!

Implementation of the main Project!

For ease of understanding & implementation, the project is been broken down into various steps & those steps are as follows:
How to fetch Docker contianer IP and then setup Webserver inside it using Ansible
By: Moiz Ali Moomin
Tags: Ansible, Docker, Dynamic Inventory, Dockerfiles, Configuration Management

Task Description:

Create an Ansible playbook that will retrieve newContainer IP and update the inventory. So that further Configuration of Webserver could be done inside that Container.

Step to Follow:

Step 1:

First You have to put the IP address of the machine or Managed_node you want to configure

The machine i am going to configure is Redhat 8 with IP address 192.168.182.130.

The Machine that has ansible installed/Controller Node is Kali Linux WSL.

The Below Picture is of Host file/inventory of ansible
Create an Ansible Playbook to load the var file and Configure Nodes
By: Moiz Ali Moomin
Tags: DevOps, Ansible, Ansible Playbook, Automation, Detection

Create an Ansible Playbook which will dynamically load the variable file named same as OS_name and just by using the variable names we can Configure our target node

Steps to follow:

Step 1:

Put the Machine IP that you want to configure with ansible
Setting Haproxy Using Power Of Ansible☺
By: Gupta Aditya
Tags: DevOps, Load Balancing, Ansible, Load Balancer, Automation

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.

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.

Inventory setup

Once All the steps are done make a new folder from the command:-

mkdir/folername

Files in Folder

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

Playbook

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 :)

Github link:-https://github.com/guptaadi123/Ansible.git
ansible-doc
Tags: Ansible, List Of Ansible Modules, Adhoc, Man Page For Ansible, Ansible Doc

Command line Syntax:-

Syntax:- ansible hostname –m module -a module arguments -i inventoryfile

The hostname argument is used to specify the managed hosts on which the ad hoc command should execute.

The -m option takes the name of the module as an argument which the ansible should run on the target nodes. Modules are programs that are executed to implement your task.

The -a option is called module arguments which are enclosed with quotes.

Some module has no additional arguments ( ex: ping ).

Modules are the tools that ad hoc commands use to complete tasks. Ansible provides hundreds of modules , each for a specific purpose.

To get list of ansible module, we can use command called ansible-doc -l

To get module documentation, we can use ansible-doc <modulename>

To learn more about modules, access the online Ansible documentation at

http://docs.ansible.com/ansible/2.7/modules/modules_by_category.html
Using Ansible to configure Docker
By: Bhavesh Kakrotra
Tags: Ansible, Docker, Apache, Automation, Linux

Using Ansible to configure Docker

In this world of automation we often require to automate a lot of things and one of them could be a container! So here we are — automating a docker container by creating an Ansible playbook!

Here we integrate Ansible and docker to create a webserver using httpd image:

First we create an Ansible playbook:

mkdir ~/playbooks

touch ~/playbooks/docker.yml

Now set your host group in inventory:

[docker]

192.168.X.Y ansible_ssh_user=**** ansible_user_pass=********

Now edit your playbook and set the tasks you want to do, and put them under in a list under tasks key. Since we are setting up a web server, our playbooks skeleton looks like:

- hosts: docker

tasks:

- name: Add Docker Repo

- name: Install Docker

- name: Enable Docker service

- name: Install Docker-py

- name: Pull httpd server image

- name: Create Volume Directory

- name: Create Link Directory

- name: Create a container

- name: Allow port on firewall

- name: Add html file

Now write down each task… until the final playbook looks like:

Now its time to execute the playbook.

On the target note we can check if the port 8080 is on.

Now put some files in the linked directory… eg:

echo "hellooooo" > /var/www/html/index.html

Now check if the webserver is running on target node:

Feel free to contact on my linkedin.
Use of Handlers in Ansible
By: Aman Rathi
Tags: Iiec Rise, Arth, Handler, Ansible, Linuxworld

In this Blog, we are going to discuss about one of the best feature of Ansible named Handlers. Above 90% module of the ansible follow the rule of idempotency. Idempotency is a functionality of Ansible by which it first check the presence of the task which it is going to do.

Lets suppose we want to install httpd software in target node by using Ansible. So during installation , it first check in target node whether the httpd software is present or not. If it exist already, the playbook show this in green color and if it does not exist, then it will perform it’s action. But there is some other modules and keywords like ‘restarted’ which doesn’t follow the idempotence rule. These modules will perform their action every time. It consume our resources and consume time also.

There is an alternative also to get rid of this situation, we can use Handlers.

What are Handlers ?

Sometimes you want a task to run only when a change is made on a machine. For example, you may want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged. Ansible uses handlers to address this use case. Handlers are tasks that only run when notified. Each handler should have a globally unique name.

# e.g of handlers in playbook

handlers:

— name: service start

service:

name: httpd

state: restarted

Here you can see that the name of the handler is ‘service start’. We have to notify this handler on change.

notify:

— service start

I am using the handlers in configuration of webserver and on changing of the conf file, port number it will notify the handlers and then handlers will restart the httpd service.

Complete code of the playbook :

# cat var.yml

- changeport: 8132

- pagedir: /var/www/arth

---------------------------------------

New configuration file which is copied to target node is :# cat lalit.confListen {{ changeport }}<Virtualhost {{ ansible_default_ipv4.address }}:{{ changeport }}>

DocumentRoot {{ pagedir }}</Virtualhost>

On running the playbook, it will also run the handlers. Here I have used 8134 port no. and it worked good.

1st time running handlers also.

Again if we play the same playbook without any Changement, it will not notify the handlers.

No handlers will be notified.

Again handlers are notified.

In the last , I used 8132 port no. and again it notifies the handlers and these will restart the service.

Thank you.
Docker Automation using Ansible
By: Gupta Aditya
Tags: DevOps, Ansible, Docker, Automation, Automation Tools

In the above picture you can see host_key_checking = False is used we might have connected to the remote system before using ansible via ssh and in that case, one key is saved in the .ssh folder to avoid the checking of that key we have used this parameter.

Once this is done install sshpass from yum install sshpass.

After this use Ansible all -m ping command to check connectivity with the remote system if all works well result will as shown below.

Firstly to configure yum in the operating system we are using the below playbook.



tasks:

— ansible.posix.mount:

path: “/dvd”

src: “/dev/cdrom”

fstype: “iso9660”

state: mounted

— yum_repository:

name: “dvd1”

baseurl: “/dvd/AppStream”

description: “new”

gpgcheck: no

— yum_repository:

name: “dvd2”

baseurl: “/dvd/BaseOS”

description: “new base os”

gpgcheck: no

— yum_repository:

name: “Docker”

baseurl: “

description: “Docker repo”

gpgcheck: no - hosts: alltasks:— ansible.posix.mount:path: “/dvd”src: “/dev/cdrom”fstype: “iso9660”state: mounted— yum_repository:name: “dvd1”baseurl: “/dvd/AppStream”description: “new”gpgcheck: no— yum_repository:name: “dvd2”baseurl: “/dvd/BaseOS”description: “new base os”gpgcheck: no— yum_repository:name: “Docker”baseurl: “ https://download.docker.com/linux/centos/7/x86_64/stable/ description: “Docker repo”gpgcheck: no

Once the yum is configured next step is to download docker and launch our container.

You can find Playbook code in GitHub attach at the end :)

To download docker we have used command module to download python3 we use yum and to download python library we have used pip module to enabling docker services we use service module and to make directory we use file module and to copy file we have template module and launching container we have used docker_container module.

You might be thinking in ansible we don't have any requirement for target node so why we have downloaded python3 here ???

This is because Ansible is using python at the backend and some modules of ansible required some specific library at the target node to run in our case we require requests,docker-py.

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 :)

Github link:-https://github.com/guptaadi123/Ansible.git
Ansible & its Features
Tags: Ansible, Ansible Playbook, Ansible Tutorial, How To Start Ansible, How To Write Playbook

What is Ansible ?

Ansible is an open source automation platform, which automates system administration tasks like package installation, patching and user management activities. In addition, it supports intra service orchestration cloud provisioning, and many other tasks.

So you think right.

Ansible is a configuration management tool that automates a system task, but it’s not the limit. It can also check the system state behavior. So here the term system state means already the package is available. Again, you’re trying to install the same package which is meaningless. Right ??

Or you can say, the services are already active where again you are trying to activate the service which is completely of no use. So here, ansible checks the system state behavior and based on that, it also perform certain action.

Lets say an example if node machine already contains package called zsh, in ansible playbook if you have written code to install package name called zsh, ansible will skip this step and it won’t install again.

So we can say ansible is an automation engine that works based on the system state.
How to configure apache webserver using ansible?
By: Shubham Rasal
Tags: DevOps, Ansible, Apache, Servers, Configuration Management

ANSIBLE-4

How to configure apache webserver using ansible?

Introduction

Redhat Ansible

Ansible is an open-source automation tool by which we can automate all cloud provisioning, configuration management, application deployment,intra-service orchestration, and many more IT needs.

Ansible is an open-source community project sponsored by Red Hat, it’s the simplest way to automate IT. Ansible is the only automation language that can be used across entire IT teams from systems and network administrators to developers and managers.

You can read more about ansible in the below article and how it helps in DevOps.

Apache Webserver

Apache is an open-source and free web server software that powers around 40% of websites around the world. The official name is Apache HTTP Server, and it’s maintained and developed by the Apache Software Foundation. It allows website owners to serve content on the web — hence the name “webserver.” It’s one of the oldest and most reliable web servers, with the first version released more than 20 years ago, in 1995.

What do we want to do?

Install an Apache web server on the managed node Configure webserver. change the document root and port number. Restart the webserver

but restarting HTTPD Service is not idempotence in nature and also consumes more resources so we have to suggest a way to rectify this and solve challenges in the Ansible playbook.

Action

Create entry of managed node in the inventory file.

You can refer to this article on how to create ssh key and use ssh public key authentication.

Create a new group named “webserver” and add a managed node server IP address there.

Write an ansible-playbook

This is my directory structure.

vars.yml file has all the variables where webserver.yml is ansible-playbook. creatorsbyheart.conf.j2 is a jinja template for changing document root and port number. my site is source-code-directory.

here we have to mention the project or website name for creating the conf file in the configuration directory.

source_code_path is the source code directory location.

webserver_conf_file is the jinja template file location

and port_number and document_root_location for configuration the webserver on that location.

Now let’s take a look at the conf file for our website

here we are reading the port number and document root from the vars.yml file through ansible-playbooks.

Here we are configuring the apache server using ansible.

In ansible, If we restart service using ansible service module… it restarts the service again. i.e it is not ideompotenet in nature. because we only to restart the webserver only if anything is changed.

so for that, we have used handlers that only get notified when we change the conf file. This way we are restarting the webserver each time we run the playbook can be avoided.
Configuring Haproxy on Aws by Ansible
By: Aman Rathi
Tags: Iiec Rise, Arth, Ansible, Haproxy, Righteducation

Here in this task, we gonna configure the haproxy server over the aws with the help of ansible.

For better understanding please go through my previous articles.

Here we simply write a playbook that includes the role of haproxy, aws, and of http .

Road Map of the Playbook

Launch aws ec2 instances with tag_name webserver and one with tag_name loadbalancer

2. Wait till these instances are ready to ssh

2. Configure the tag_name webserver with http role and of tag loadbalancer with haproxy role

Playbook
Ansible: Setting up Hadoop cluster using ansible playbook
By: Yashraj Oswal
Tags: Vimal Daga, Ansible, Arthbylw, Hadoop Cluster, Righteducation

Introduction:

Ever thought setting-up Hadoop cluster will be so simple? Like you just need to run an ansible play-book, that’s it!. Yes, today we are going to learn how we right from installation and configuring hdfs-site.xml and core-site.xml file in both master and slave nodes, create hadoop cluster within a few seconds of time.

So lets get started….!

Setting-up inventory file: Add IP addresses of Master node and slave node:

Below is the image where we have created .txt file in which host-name [Master] and [Slave] is created.

Now in this file we need to add ip address, username of system where you are configuring master node and password of that system and as we are configuring a linux system, connection protocol used is ssh.

To get more details about how we can configure ansible, read my blog, Ansible: Configuring httpd inside docker container. In this blog I have explained the pre-requisites.

Let us check whether JDK and Hadoop are present on the manage nodes or not:

Now let us design ansible playbook:

Master code: Explanation..

Slave Node : Explanation…

***Note that above two pictures are just for easy illustration, both master and slave are included in one single play book***

Now let us run the playbook, and see what happens….

Command: ansible-playbook hadoop.yml

Here, the master has configured successfully…..

Here the code execution has completed successfully….!

Now let us check JDK and Hadoop are installed or not:

As you can see both JDK and Hadoop has installed successfully…!

Now let us check whether Master node/Name node and Slave node/ Data node has started or not:

First we will check whether Master node/Name node has started or not:

Lets check Data node as well:

Great..! So now next step is to check connection:

So here we have successfully connected Data node with Name node..!

Thank-you..!
Configure a container as apache web server using Ansible as a configuration management tool
By: Prakhar Khandelwal
Tags: Vimal Daga, Ansible, Arthbylw, Automation, Righteducation

Hello Guys !!!

Today , in this article we will learn how to configure a container as a apache web server using the ansible as a configuration management tool…

Before going for the above task ,let me give to a brief high level idea about the container , apache web server , and the ansible

What is container??

When ever we launched any os(operating system) with the help of any container technology based tool like docker , then the os launched is named as container.. Like whenever we launched any os on the top of any virtualization program like VirtualBox etc , the os launched are named as Virtual Machine something like that…. Although , the docker is not same as Virtualization , both are different technologies… For eg -: In Virtualization technology installing and booting of consumes a lot of time (typically 5–15 mins depends upon hardware quality like ram , cpu etc..) , but with the help of docker we can install + boot + login to the console of the os(container) hardly in 1 second… That’s the reason , why most of the companies/organizations are shifting towards container based tools like docker , podman etc…

Hope , you get the high level idea about the container….:)

What is Apache Web Server???

Web server is a program which we install on the top of our os for hosting our website/WebApp… Now , there are many software present in the market for configuring os as web server.. Apache(a community) also provides a software/package name httpd(for redhat distributions),apache2 (for fedora distribtions) , therefore typically we named these softwares as apache web server

What is Ansible???

Ansible is a tool , build on the top of python(means it is a python library). Ansible is used for doing configuration management, in intelligent and declarative way….

Ansible , provides the benefit of the RAL(Resource Abstraction Layer) .. This , RAL feature of ansible helps the admin guys a lot… With , the help of this feature , admin guys can easily configure any type of os without even knowing their commands… So, ansible helps a lot in doing the configuration management , in heterogeneous environment…

Now , after getting high level idea about the above topics , let’s jump to the task..!!

Task Description-:
Handlers in Ansible.
By: Lalit Yadav
Tags: Vimal Daga, Arth, Ansible, Automation, Righteducation

In this Blog, we are going to discuss about one of the best feature of Ansible named Handlers. Above 90% module of the ansible follow the rule of idempotency. Idempotency is a functionality of Ansible by which it first check the presence of the task which it is going to do.

Lets suppose we want to install httpd software in target node by using Ansible. So during installation , it first check in target node whether the httpd software is present or not. If it exist already, the playbook show this in green color and if it does not exist, then it will perform it’s action. But there is some other modules and keywords like ‘restarted’ which doesn’t follow the idempotence rule. These modules will perform their action every time. It consume our resources and consume time also.

There is an alternative also to get rid of this situation, we can use Handlers.

What are Handlers ?

Sometimes you want a task to run only when a change is made on a machine. For example, you may want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged. Ansible uses handlers to address this use case. Handlers are tasks that only run when notified. Each handler should have a globally unique name.

# e.g of handlers in playbook

handlers:

— name: service start

service:

name: httpd

state: restarted

Here you can see that the name of the handler is ‘service start’. We have to notify this handler on change.

notify:

— service start

I am using the handlers in configuration of webserver and on changing of the conf file, port number it will notify the handlers and then handlers will restart the httpd service.

Complete code of the playbook :

# cat var.yml

- changeport: 8132

- pagedir: /var/www/arth

---------------------------------------

New configuration file which is copied to target node is : # cat lalit.conf Listen {{ changeport }} <Virtualhost {{ ansible_default_ipv4.address }}:{{ changeport }}>

DocumentRoot {{ pagedir }} </Virtualhost>

On running the playbook, it will also run the handlers. Here I have used 8134 port no. and it worked good.

1st time running handlers also.

Again if we play the same playbook without any changement, it will not notify the handlers.

No handlers will be notified.

Again handlers are notified.

In the last , I used 8132 port no. and again it notifies the handlers and these will restart the service.

Thank you.
Configuring Haproxy by Ansible
By: Aman Rathi
Tags: Iiec Rise, Vimal Daga, Arth, Ansible, Haproxy

Here in this task we gonna see how to configure the haproxy server with the help of ansible.

Haproxy

HAProxy is a free, open-source software that provides a high availability load balancer and proxy server for TCP and HTTP-based applications that spread requests across multiple servers. It is written in C and has a reputation for being fast and efficient.

Road map of Ansible role of Haproxy

Make an inventory that contains the webserver’s ip Edit the config file by jinja template Now install the haproxy software Start the service Copy the config files Restart the service

Lets’s see step by step

Step1. Making inventory

We will create two different groups one contains the load balancer IP and the other one contains the webservers IP. So that the haproxy fetch the IP from the inventory and save them in the config file.

Step2: Editing the file by jinja template

Set the webservers ip in the haproxy.cfg file by jinja templates

Step3. Installing the haproxy software

The first task of this role is to install the haproxy server’s software

- name: installing haproxy

package:

name: haproxy

state: present

Step3. Starting the service

- name: starting services

service:

name: haproxy

state: started

Step3. Copying conf. files and restarting the service

Hereafter copying, we have to restart the services for this we will use handlers and this notify keyword notifies handler to restart the service.

- name: copying files

template:

src: haproxy.cfg.j2

dest: /etc/haproxy/haproxy.cfg

notify: restart

Now let’s create a playbook to which will first create a webservers on thr provided ip’s and then attach with haproxy. For the webserver role use the below github link.

- hosts: webserver

gather_facts: no

tasks:

- name: setting up webservers

include_role:

name: http

- hosts: loadbalancer

gather_facts: no

tasks:

- name: setting up load balancer

Output

Here all the webservers are running on 8123 ports with diff ip’s but we only need on one ip i.e of loadbalancers ip and we will be redirected to the webservers.

github links

Thank You!!
Create an Ansible playbook that will retrieve container IP and update the inventory. So that further Configuration of the Webserver could be done inside that Container.
By: Ritesh Singh
Tags: Apache2, Ansible, Docker

Create an Ansible playbook that will retrieve container IP and update the inventory. So that further Configuration of the Webserver could be done inside that Container. Ritesh Singh Dec 14, 2020·3 min read

Prerequisite :

✅ Docker Installed.

Solution:

First, we need to make one playbook for updating inventory, for this, I have jinja 😅 in Playbook, After that use hosts name for configuring the web server in the docker container.

Step-1)Make one Docker image, add user, configure the password, and enable ssh

To make it simple I am using Dockerfile.

FROM ubuntu:latest

RUN apt update && apt install openssh-server sudo -y

RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test

RUN echo "test:test"| chpasswd

RUN service ssh start

RUN echo "test ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

EXPOSE 22

CMD ["/usr/sbin/sshd","-D"]

Here I am using ubuntu:latest

For changing the pass of the user use chpasswd command.

After that also need to give power to this user, we need to add, USER_NAME ALL=(ALL) NOPASSWD:ALL in the /etc/sudoers.

in the Build the Dockerfile.

docker build -t NAME_OF_IMAGE .

After this launch one container 😉.

docker run -dit --name NAME_OF_CONTAINER -p 21:22 4444:80 NAME_OF_CONTAINER

Step-2)Retrieve the name and Ip of the container.



tasks:

- name: Retrive Name of Docker Container

shell: "docker ps --format '{% raw %}{{ .Names }}{% endraw %}'"

register: Name - name: Retreive Ip of Docker Container

shell: "docker inspect --format '{%raw %}{{ .NetworkSettings.IPAddress }}{% endraw %}' $(docker ps --format '{% raw %}{{ .Names }}{% endraw %}')"

register: IP

Here I have used jinja because we need to retrieve the name and IP.

We need to register also because by using these vars we can update the inventory.

Step-3)Updating inventory

blockinfile:

path: /mydb/inventory.txt

block: |

{% raw %}[{% endraw %}{{ Name.stdout }}{%raw %}]{% endraw %}

{{ IP.stdout }} ansible_ssh_user=test ansible_ssh_pass=test

Here I have used the blackinfile module for configuring inventory.

I have also used jinja here because we need to write group name with [] brackets, for passing [] brackets as string in inventory, and {{ Name. stdout}}, {{ IP.stdout }} as variable 🤯.

Step-4)Configuring Webserver in the Docker container.

- hosts: NAME_OF_Container

become: yes

become_user: root

become_method: sudo tasks:

- name: Installing webserver(apache2)

apt:

name: apache2

state: present - name: Starting service

service:

name: apache2

state: started

I have used ubuntu:latest , so for ubuntu, I have installed apache2

Use privilege escalation for sudo.

Output 👊

Inventory updated

Use IP:4444(port)

Github Link
Use Ansible to setup HAproxy as a Load Balancer
By: Priyanka Bhide
Tags: Haproxy, Ansible, Load Balancer

What is HAProxy ?

HAProxy is a high-performance, open-source load balancer and reverse proxy for TCP and HTTP applications. Users can make use of HAProxy to improve the performance of websites and applications by distributing their workloads. Performance improvements include minimized response times and increased throughput. HAProxy is used in high traffic services such as Github and Twitter.

HAProxy Architecture :

Load balancers can be used to distribute workloads across computers, networks, disk drives or CPU’s. A reverse proxy accepts a request from a client, forwards it to a server that can fulfill it, and returns the server’s response to the client. A load balancer distributes incoming client requests among a group of servers, in each case returning the response from the selected server to the appropriate client.

What is Ansible ?

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code.

Let’s start the configuration in Ansible …👇

Follow the below steps in Controller Node(CN) :

Step-1 : In CN, create a inventory file which consists of IP’s of load balancer and webservers.

Step-2 : Check the network connectivity to the webservers as well as load balancer using ping module.

ansible host_name -m ping

Step-3 : Create an ansible playbook (lb.yml) containing all configuration of webserver and HAProxy server(Load balancer).

Step-4 : To update HAProxy Configuration file automatically on each time , write the below code at the last in “haproxy.cfg.j2"

Step-5: Run the playbook using command :

ansible-playbook lb.yml (playbook_name)

Step-6: Check the Managed Node (load balancer) , configuration file is updated dynamically. (/etc/haproxy/haproxy.cfg)

The port no. is changed to 8081.

It’s adding entry of every webserver present in the inventory file of CN.

Step-7: Check the working of load balancer on client browser, as the Client uses load balancer IP only, it doesn’t know from which webserver it is getting the content.

Task completed !✌️

Thanks for Reading !!🙏
Ansible Playbook to configure docker, enable it’s services and start the webserver
By: Shreya Kumari
Tags: Ansible, Ansible Playbook, Docker, Apache Web Server

If you want to accomplish the following tasks using ansible playbook, you have landed on the correct source!

🔹 Configure Docker

🔹 Start and enable Docker services

🔹 Pull the httpd server image from the Docker Hub

🔹 Run the docker container and expose it to the public

🔹 Copy the html code in /var/www/html directory and start the web server

Let’s see step by step, how we can use ansible to get our task done.

First of all, we create a file named docker.repo and write the following text into it. It basically provides the path from where docker shall be pulled.

Now, we shall write a playbook in which, we shall use the copy module, to copy docker.repo on the target node.

We provide the destination which specifies where we need to copy the particular file and source which states where the file currently resides.

Next, we use package module, which specifies the name of the package we need to configure.

Lastly, we use the service module to start the docker services. We run this file, and hence we have configured and enabled docker, completing 2 of the required use cases.

Now, we shall pull the image from the docker hub. The name of the image is “httpd” as mentioned in the question.

The next step is to expose the port to public and allow the firewall on the specific ports.

Now, we shall create an html file named t10.html and copy it to the target nodes.
Configuring Docker, enabling it’s services, and starting the webserver via Ansible Playbook…
By: Abhishek Kumar
Tags: Ansible, Docker, Apache, Automation, Httpd

Docker via ansible

1. First of all we will create a workspace

mkdir /wstask10

2. Create a repo file for Docker:

vim docker.repo

It basically provides the path from where the docker shall be pulled.

docker.repo

3. Create a HTML file to copy to the Target Node and Host the webpage

vim task.html

Content of html file is shown below:

4. Now the most important thing left, which is playbook. As Ansible uses Playbook to perform the tasks sent from the Controller node to the Target Node.

So will write yml file used by ansible

vim preq.yml

1

In this first we Copied the repo file of docker.

Then Confirm for the docker image to be pulled into that repo location.

After that starting the docker services.

Then finally pull docker image.

After this,

2

After this we created Docker container with some syntax of Ansible.

Then, Firewall configuration for both port and exposed ports

Finally I copied the html file in the Document root and I also shown the content of webpage above.

copy from src to dest

Now, here is the list of all the files in my workspace of this task.

list

Finally, We have to Run the Playbook and this can be done by

Ansible-playbook <filename>.yml

Anyone can also use verbose(-v) for more details in between filename and playbook.

So here is the result of running playbook.

playbook ran successfully.

Finally Our work for control Node is over.

Now we can go to Target Nodes and check about the Port numbers running there. Webpage copied in document root or not and many more which is needed to verify you.

Just use

tcpdump — tnlp

to catch all the running ports.

I am running the Webpage hosted by target node. So I will use

IP/filename in the browser.

Here, 192.168.43.174/task.html
Ansible Handlers!
Tags: Vimal Daga, Arth, Ansible, Linuxworld, Automation

* Ansible-

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning. Automation is crucial these days, with IT environments that are too complex and often need to scale too quickly for system administrators and developers to keep up if they had to do everything manually. Automation simplifies complex tasks, not just making developers jobs more manageable but allowing them to focus attention on other tasks that add value to an organization. In other words, it frees up time and increases efficiency.

What is idempotency?

The principle that enables Ansible to be declarative and yet reliable is idempotence, a concept borrowed from mathematics. An idempotent operation is one that can be applied multiple times without changing the result beyond the initial application, such as multiplication by zero.

In lay-man words, idempotence is the concept of re-doing an operation without bringing a change in it. Like you multiply a number with 0,will always give you the same result no matter how many times the action has been performed.

Restarting the service!

Started/Stopped are idempotent actions that will not run commands unless necessary, i.e if a service is already running, then ansible will skip this task of starting a service and not consume CPU time same applies to a stopped service,but restarted will always restart a service even if changes were not made.

For eg- Consider a basic playbook for setting up HTTPD in the target node.

Now when you run the service

Certain changes take place as shown in the picture, but when you again run the playbook (ansible-playbook <filename>.yml).

Again changes are made on the same playbook for some reason, hence it contradicts idempotancy.

To solve this problem HANDLERS are used.

Handlers-

Sometimes you want a task to run only when a change is made on a machine. For example, you may want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged. Ansible uses handlers to address this use case. Handlers are tasks that only run when notified. Each handler should have a globally unique name.

Running a playbook with handlers!

As it is clearly visible that no change takes place, hence handlers are useful for maintaining idempotancy in ansible!
Configuration of HAProxy using Ansible
By: Samar Pratap Singh
Tags: Load Balancing, Ansible, Ansible Playbook, Haproxy, Configuration Management

Configuration Management has always been an important task, mostly for installing, uninstalling, tracking and controlling changes in software or rather we can say in an Operating System. But manually configuring multiple no. of OS or servers is a tedious & error-prone job. Generally in companies, we have 100s or1000s or millions of servers depending upon the scale of the companies. Hence, there is no other way other than Automation.

Here, we are going to discuss What is Ansible, What is HAProxy, & how HAProxy can be configured along with web servers using the most used Configuration tool today named Ansible. I’ve created a diagram of the infrastructure we are going to configure using Ansible:
Restarting Httpd Service is not idempotent, how to make the Service Idempotent.
By: Abhishek Kumar
Tags: Idempotency, Ansible, Ansible Playbook, Apache, Httpd

Hello Everyone,

First of all, we should know what is idempotence,

Idempotence: Idempotence means that applying an operation once or applying it multiple times has the same effect. Examples: Multiplication by zero. No matter how many times you do it, the result is still zero.

When we make any changes in the configuration files then only we restart any service. If we are executing a command to restart the service it will consume compute resources.

When we run ansible-playbook for restarting the service of httpd. It will again restart the service at the target node but I want the service to only restart when I make any change to configuration files otherwise it will not restart the service of httpd and save the compute resources.

For achieving the idempotence we will use the handler module and notify task in ansible.

notify

List of handlers to notify when the task returns a ‘changed=True’ status.

handlers module in ansible

Sometimes we want a task to run only when a change is made on a machine. For example, We may want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged. Ansible uses handlers to address this use case. Handlers are tasks that only run when notified.

I have written the playbook for this giving example :
Using Ansible Play Book Docker Configuration →>>
Tags: Ansible, Ansible Playbook, Docker

what is 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.

what is docker ?

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.

what is ansible playbook?

An Ansible playbook is an organized unit of scripts that defines work for a server configuration managed by the automation tool Ansible. Ansible is a configuration management tool that automates the configuration of multiple servers by the use of Ansible playbooks.

so here we go

first we have to create yum repo in target node we don’t have write now docker-ce software in redhat dvd. So we are going to create yum repo and after that we are going to install docker software.

so we successfully created docker repo and install docker software which are not present in target node.

but now we have to start the docker services.

here we can see the services started .

now we don’t have any images so we have to pul l docker image from docker hub .

here we can see the docker image came.

using this ansible code we can download docker software and start the docker services and also pull the images from docker hub.

we don’t have any running container so for running container

using the code we can run docker container usnig ansible palybook.
Deploying Apache webserver In Docker container by Ansible
By: Lalit Yadav
Tags: Vimal Daga, Http Server, Ansible, Docker, Automation

In this article, I am going to show how to deploy apache webserver in docker container by using ansible.

Here I am using an AWS ec2 instance as a target node coz it is a fresh new operating system and there is nothing preconfigured. Now start the task:

Configure your local system:-

# pip3 install boto

# pip3 install boto3

-----------------------

Download ec2.py and ec2.ini file by wget <below_url>from the given URL: https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini -------------------------------

Create a folder(e.g. /etc/ansible/hosts) and move these files to this folder. Make these files executable: # chmod +x ec2.py

# chmod +x ec2.ini

-----------------------------------

Now export the credentials in your system: # export AWS_REGION=’ap-south-1'

# export AWS_ACCESS_KEY_ID=’XXXXXXXXXXXXXXX’

# export AWS_SECRET_ACCESS_KEY=’XXXXXXXXXXXXXXXX’

------------------------------------

Put your aws key in your localsystem and provide the path of the key in ansible.cfg file.

Then change the format type of the key.

# chmod 600 <keyname.pem>

The ansible.cfg file should be as:

# cat ansible.cfg

[defaults]

host_key_checking=False

remote_user=ec2-user

ask_pass=False

private_key_file=/etc/ansible/key/firstkey.pem

roles_path=/etc/ansible/roles [privilege_escalation]

become=True

become_user=root

become_method=sudo

become_ask_pass=False

For more info about connectivity with AWS instance by using ansible, you can go through my previous articles:
Ansible Role : Some Pointers. Some Ansible Role Related Pointers:
By: Deepak Kashyap
Tags: Ansible, Ansible Roles, DevOps

Some Ansible Role Related Pointers:

1. ‘pre_tasks’ executes before roles in a playbook

2. ‘handlers’ do get executed at end of the play so beware it is not end of task file or playbook

3. ‘handlers’ are mostly used for ‘Restarting services’

4. Roles are a way of automatically loading certain vars_files, tasks, and handlers

5. Role’s task directory contains main.yml which is basically a YAML list of tasks

6. ‘tasks’ is one of the mandatory subdirectories to be present within a role directory structure

7. Default sequence for role and playbook task execution : Role tasks execute before playbook tasks

8. ‘roles_path’ has to be set in ansible.cfg to configure a specific path for Ansible to look for roles

9. Meta directory in the roles can contain Dependencies on other roles

10. If roles/rolename/vars/main.yml exists then Those variables overrule defaults/main.yml in that role

11. Defined process for creating and using a role: Create the role directory structure; define the role content; use the role in a playbook

12. Remember using role defaults is least important in terms of variable precedence

13. A role can run multiple times as a dependency if allow_duplicates is set to “true” or “yes”

14. Ansible Galaxy be used to install roles from the Ansible community to your playbook directories

15. Only if the file contains role names in the “username.rolename” format you install multiple roles from Galaxy using a file with a list of role names

16. “ansible-galaxy init newrole1 -p /etc/ansible/roles” command when executed installs a role by the name of “newrole1” at /etc/ansible/roles

17. Ansible Galaxy is a collection of community contributed roles
Configure Reserve Proxy over the EC2 instance in a minute with Ansible
By: Adamaya Sharma
Tags: DevOps, AWS, Load Balancing, Ansible, Ec2

A load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Load balancers are used to increase the capacity (concurrent users) and reliability of applications.

HAProxy (High Availability Proxy) is a TCP/HTTP load balancer and proxy server that allows a webserver to spread incoming requests across multiple endpoints. This is useful in cases where too many concurrent connections over-saturate the capability of a single server.

Ansible is an automation tool that helps to configure the HAproxy.

let's start configuring the HAproxy load balancer on the AWS ec2 instances using ansible-playbook.

Steps

firstly launch 3 instances of RHEL 8 on the AWS named load balancer, webserver1, and webserver2. make sure they all are in the same subnet.