BigBulls Game Series- Patching MongoDB using Ansible

MongoDB is the most popular NoSQL and an open-source document-oriented database. The term NoSQL means ‘non-relational’.This simply means mongo does not base on a table-like relational database structure. It is moreover a schemaless database. In Mongo information is stored in JSON-style documents.

What is Patching?

1. A patch is a set of updates containing a delta of changes between two different versions.

2. Patching is basically done to fix security-related vulnerabilities.

3. Patch is aimed to add a new functionality and remediates current bugs to keep our system updated and secure from attacks.

4. Some patch updates also help us in fixing issues with drivers and software running on the system.

5. The longer a server is unpatched, the bigger is the risk of cyber-attacks. A golden thumb rule is to apply patches within 30 days of vendors making them available.

Factors to be considered while Patching-
When we are patching any application server or a database server the First thing that comes to our mind is there should be no downtime in both cases.
When a hole is found, patching seems obvious. At the same time, we need to look at the total hours and money spent patching versus the cost of downtime.
Here are some important key factors to consider –

1. Cost of lost data– When we are patching any server this is a possibility of data loss. So we should have a replication of the data/DR system so that we should not suffer any data loss which could affect our business reputation.

2. Downtime costs– Downtime simply means when the application is not available to serve requests which can be due to any region either technical glitch, network outage. Downtime can potentially paralyze your organization, and in some cases, even cause irreparable damage.

As we have discussed basic factors to be considered while patching. Now let’s get started with the important things which we have to keep in mind which patching and rebooting a MongoDB cluster-

1. While patching a server either it is (application or database) in this case we are taking database(MongoDB) we have to exclude all the application and database-related packages.

2. Before taking reboot we have to take backup of all the indexes collection with respective of service database.

3. While rebooting a MongoDB cluster we have to keep in mind that first, we have to reboot secondary nodes and then go for primary nodes.

4. After reboot when primary nodes come up you need to verify the indexes collection should be the same as it was before the reboot.

Introduction to Ansible Role- As we all know that in today’s world is all about automation. Especially when we talk about the DevOps lifecycle we always try to automate tasks. Patching is an important aspect when we talk about security. Automating it will help us to patch more servers in a single click.
Here is the Ansible role for patching a mongo cluster

git repo link

1. Firstly clone the repo-

2. Then using the following command you can start patching your mongo cluster-

Below recording will help you in understanding the working of Ansible role-

Patching simply means keeping your servers updated so that there is no security breach. Effective patch management process requires a combination of automation and best practices. With the right patches in place, it improves the functionality and performance of your infrastructure. At the same time, it can also improve uptime, error rates, system-level performance metrics.
If you enjoyed this article, share it with your friends and colleagues!”

Image Reference

Blog Pundit: Bhupender rawat and Abhishek Dubey

Opstree is an End to End DevOps solution provider

Connect Us

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: