I have two machines hosting one mongo instance each.
I need them to work together as a replica set.
I use Ansible for my provisioning.
How can I achieve that ?
This is how I managed it.
I used Stouts.mongodb from Ansible Galaxy.
In playbook.yml
:
---
- name: Provision database servers
hosts: dbservers
sudo: true
vars:
mongodb_conf_replSet=rs-name/db-hostname-1:27017,db-hostname-2:27017
mongodb_shell:
db-name:
- rs.initiate()
roles:
- Stouts.mongodb
See the mongo doc for more details about how to set up a replica set.