Deploy Percona Server for MongoDB Replica Set With AnsibleIn this blog post, we will discuss deploying a Percona Server for MongoDB (PSMDB) replica set with Ansible*. Ansible is a popular automation tool that can configure systems, deploy software, and orchestrate more advanced tasks like continuous deployments or zero downtime rolling updates. Its main goals are simplicity and ease of use. By default, it uses the SSH protocol to connect to the server. To know more about it, please go through the documentation.

With Ansible, one can easily configure and deploy the PSMDB replica set (RS). Kindly follow the installation instructions of the Ansible for the respective operating system.

Prerequisites

  • A user must be created, usually “percona” for OS.
  • The OS user (in our case it’s “percona”) needs password-less sudo on the db server.
  • Ansible
  • SSH access from control node to all the DB servers as Ansible uses the SSH protocol to connect to the server.

Below is the inventory, in which we have specified the host’s info.

Inventory:

 

Global variable file all defined in group_vars

 

The playbook main.yml for the Deployment of PSMDB RS is below. Here, we are sharing a high-level TASK to deploy the replica set. To get the complete main.yml playbook, please check the GitHub link.

 

Execute the playbook as below:

 

If the playbook has been executed successfully, you’ll see output like the below (here showing the trimmed output of the playbook i.e the recap of the playbook):

 

Let’s connect to mongo and verify if PSMDB RS deployment has been set up.

 

From the above, we can see, PSMDB RS has been deployed successfully. Our automation with Ansible to deploy a replica set worked properly.

Conclusion

Ansible is the most popular simple, ease-of-use automation tool and plays a major role in configuring systems, deploying software, and continuous deployment. With Ansible, we have easily deployed a PSMDB RS with ease by defining tasks in a playbook. 

We also encourage you to try our products for MongoDB like Percona Server for MongoDB, Percona Backup for MongoDB, and Percona Operator for MongoDB.

*Disclaimer: This blog explains how Ansible can be used to deploy a Percona MongoDB replica set. Ansible is not a Percona product and is not supported by Percona. The information in this blog post is intended for educational purposes only. 

Percona Distribution for MongoDB is a freely available MongoDB database alternative, giving you a single solution that combines the best and most important enterprise components from the open source community, designed and tested to work together.

Download Percona Distribution for MongoDB Today!

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Peter Colclough

Would it not be a better idea to set MongoDB up as a single sharded cluster? IMO, data grows, and making that decision later on only leads to a major pe=iece of work, identifying shard keys, setting up the shards, and putting in place what should have been here from the get go?

I have also found that, although the ‘priority’ is little used these days, actually assigning the priority to a physical hierachy, dictating which machines will take over in case of an outage, works better. This also allows one machine to be used as a place to take the backup from, for that shard. I have also found it useful to have a small machine for an Arbiter also…. just helps it make the right decision if a splu=it brain happens.

Apart form that , a great article.