Deploy the MongoDB Replica set using Ansible.
Pre-requisite:
Make sure to add hosts entries in /etc/hosts in all mongod instance. Verify whether it's reachable, i.e within network. Check it with ping or telnet. ping hostname/ip telnet hostname/ip mongo_port Quick guide
Adjust the hosts details in inventory. Adjust the global variables in group_vars/all
Run the playbook --> main.yml ansible-playbook main.yml -i inventory Inventory file --> Inventory file should contain fully qualified domain. It has been tested against that. Keep a separate inventory file per environment (for example dev, test, prod).
For each standalone replicaset you should name them rsXXXX.
Example of inventory for a Replica Set:
[rs1] fully-qualified-domain1 mongodb_primary=True fully-qualified-domain2 fully-qualified-domain3
Configuration The all variables file contains all the user-modifiable parameters. Each of these come with a small description to clarify the purpose, unless it is self-explanatory. You should review and modify this file before making the deployment. Running The playbook is meant to handle a deployment from scratch, unless run with some specific tags (e.g. conf). So be extra careful if you are running it against servers that already have data.
Cleanup If you want cleanup a failed deploy, usually stopping mongod components and removing the datadir content is enough e.g. service mongod stop; rm -rf {{ mongod_path }}/* Connecting Connection string example with TLS mongo --tls --tlsCAFile /tmp/test-ca.pem --tlsCertificateKeyFile /tmp/test-client.pem --port 27017 --host -u -p