opstree_devops.mongo
OSM: MONGODB
This is an Ansible role for setting up MongoDB as a standalone instance or in a cluster with replication and authentication.
Version History
Date | Version | Description | Changed By |
---|---|---|---|
27 June 2020 | v0.0.1 | Initial draft | Rajat Vats |
21 March 2022 | v0.0.2 | Node DNS management | Kritarth Pant |
PREREQUISITES
NONE !!!!
SUPPORTED OPERATING SYSTEMS
Ubuntu 18
CentOS 7
Amazon Linux 2
FEATURES
- Set up a standalone MongoDB instance
- Configure replication for a MongoDB cluster
- Enable authentication with root, admin, and backup users.
IMPORTANT VARIABLES
Variable | Default Value | Possible Values | Description |
---|---|---|---|
mongo_version | 4.2 | [4.2, 4.0, 3.6, 3.4] Minor versions can also be specified, e.g., 4.2.7 | Version of MongoDB |
mongo_port | 27017 | As needed | MongoDB port |
replication_enabled | false | [true, false] | Set to true to enable replication |
mongo_replSetName | repl | As needed | Name of the replica set |
authentication_enabled | true | [true, false] | Set to true to enable authentication for predefined users: root, admin, and backup |
mongo_user_admin_name | useradmin | Default value can be changed | MongoDB admin username |
mongo_user_admin_pwd | passw0rd | Default value can be changed | MongoDB admin password |
mongo_root_admin_name | RootAdmin | Default value can be changed | MongoDB root username |
mongo_root_admin_pwd | passw0rd | Default value can be changed | MongoDB root password |
mongo_root_backup_name | backupuser | Default value can be changed | MongoDB backup username |
mongo_root_backup_pwd | passw0rd | Default value can be changed | MongoDB backup password |
mongo_custom_users | None | Can define multiple users with roles. See example below for reference. | |
mongo_authentication_key | Enter your key here. (GPG key) | Key for secure communication between cluster nodes. |
Define Multiple Users in MongoDB
mongo_custom_users:
- { name: user1, password: userpwd, roles: admin }
- { name: user2, password: userpwd, roles: backup, clusterMonitor }
INVENTORY EXAMPLE
Here’s a sample inventory setup:
[mongo_master]
prim ansible_ssh_host=3.1.x.x
[mongo_slave]
sec1 ansible_ssh_host=18.141.x.x
sec2 ansible_ssh_host=54.169.x.x
[mongo:children]
mongo_master
mongo_slave
[mongo:vars]
ansible_user=ubuntu
PLAYBOOK EXAMPLE
An example playbook to execute this role:
---
- hosts: mongo
roles:
- osm_mongo
become: true
any_errors_fatal: true
USAGE
ansible-playbook -i hosts site.yml