Ansible role which installs and configure a mongodb replicaSet. MongoDB
- Install and configure a mongodb simple replicaset, with 1 primary and x secondaries
- All secondaries replicate the data and are eligible to become primary nodes
- Uses a keyfile for internal authentification inside the cluster
- Schema of the replicaSet created :
Here is the list of all variables and their default values:
# Paths
mongo_path: /data/mongodb # Parent dir for data,logs and keyfile
mongo_data_path: "{{ mongo_path }}/data" # Where to store the data
mongo_log_path: "{{ mongo_path }}/log" # Where to store the logs
mongo_keyfile_path: "{{ mongo_path }}/keyfile" # Where to store the keyfile (used for internal authentification)
# ReplicaSet
mongo_replset_name: jim # Name of the replicaset
mongo_replset_init: false # Initialize the replicaset, set to true on first run only
mongo_replset_members: ['hostname1', 'hostname2', 'hostname3'] # Hostnames of your servers, where to deploy the replicaset
mongo_replset_primary: "hostname1" # Hostname of the primary, which server will be the primary
# Content of the keyfile, must generate it with openssl rand -base64 756
mongo_keyfile_content: ''
# Tuning
mongo_transparent_hugepage_disable: true # Disables transparent_hugepages and transparent_hugepages_defrag
# Admin User
mongo_admin_user: 'admin' # Admin username
mongo_admin_password: 'passwd' # Admin password
# Logrotate
mongo_logrotate: yes
mongo_logrotate_options:
- compress
- copytruncate
- daily
- dateext
- rotate 7
- size 10M
Clone the repo.
$ git clone https://github.com/jdelvecchio/ansible-role-mongodb
Then set vars in your playbook file.
Example with minimum required variables :
- hosts: mongodb_servers
gather_facts: yes
become: yes
roles:
- role: ansible-role-mongodb
mongo_replset_init: true
mongo_replset_members: ['hostname1', 'hostname2', 'hostname3']
mongo_replset_primary: "hostname1"
mongo_keyfile_content: |
sbOJJ2eEY4mUg24KUkkQgdYy+EOzNXKRCqiFhhK2a8Zv5h9SqfR7vySGSaBLMMZW
Sk3K5ZHh++PVKyTJrnuvVsNT/oRku7ji+YeSKNqAKtWgm+ktci3/PzNk3gP9SzZC
5KjQF/ClnwWpeZ76NIIB8te9izBDdQ/eOorYFNfmtS2PSuR2LcRvK77jUn5qkNFW
9aqxUTjvCJxfOwVXpE9fHkhgbF0qlO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