Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I setup mongo replica set with ansible?

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 ?

like image 276
Raphaël Avatar asked Mar 16 '23 01:03

Raphaël


1 Answers

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.

like image 128
Raphaël Avatar answered Mar 17 '23 17:03

Raphaël