Skip to content
Snippets Groups Projects
Verified Commit d4f673fd authored by nd's avatar nd
Browse files

add cluster, user creation and replication setup support

parent 76f01a03
Branches
No related tags found
No related merge requests found
mongodb:
version: "4.2"
api_user: "{{ omit }}"
api_password: "{{ omit }}"
config:
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: 127.0.0.1
processManagement:
timeZoneInfo: /usr/share/zoneinfo
replication:
replSetName: rs01
backup:
enable: true
keep_days: 2
- name: install pymongo from pip because the debian version is too old
pip:
executable: pip3
name: pymongo
- name: copy mongodb config
notify:
- restart mongodb
......@@ -16,6 +21,36 @@
daemon_reload: yes
enabled: yes
- name: flush handlers
meta: flush_handlers
- name: create replica sets
retries: 3
delay: 5
loop: "{{ mongodb.replicaset|dict2items }}"
community.mongodb.mongodb_replicaset:
login_host: "{{ mongodb.config.net.bindIp }}"
login_port: "{{ mongodb.config.net.port }}"
login_user: "{{ mongodb.api_user }}"
login_password: "{{ mongodb.api_password }}"
replica_set: "{{ item.key|d(mongodb.config.replication.replSetName) }}"
members: "{{ item.value.members }}"
validate: no
- name: create mongodb user
no_log: true
loop: "{{ mongodb.user|dict2items }}"
community.mongodb.mongodb_user:
login_host: "{{ mongodb.config.net.bindIp }}"
login_port: "{{ mongodb.config.net.port }}"
login_user: "{{ mongodb.api_user }}"
login_password: "{{ mongodb.api_password }}"
name: "{{ item.key }}"
password: "{{ item.value.password }}"
roles: "{{ item.value.roles }}"
database: "{{ item.value.database|d('admin') }}"
replica_set: "{{ item.value.replica_set|d(mongodb.config.replication.replSetName) }}"
- include_tasks: backup.yml
when:
- mongodb.backup.enable
......@@ -2,43 +2,7 @@
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
replication:
replSetName: rs01
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
#
# {{ ansible_managed }}
#
{{ mongodb.config|to_nice_yaml }}
packages:
pkg:
"python3-pip": {}
"mongodb-org": {}
repos:
mongodb:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment