From 0d4556869838da58bf4c3d8e7019291ea569826e Mon Sep 17 00:00:00 2001
From: nd <git@notandy.de>
Date: Sat, 19 Dec 2020 20:11:13 +0100
Subject: [PATCH] fix mongodb config

---
 tasks/main.yml           | 14 ++++---------
 templates/mongod.conf.j2 | 44 ++++++++++++++++++++++++++++++++++++++++
 vars/main.yml            |  2 ++
 3 files changed, 50 insertions(+), 10 deletions(-)
 create mode 100644 templates/mongod.conf.j2

diff --git a/tasks/main.yml b/tasks/main.yml
index 2fa8b5e..97844b6 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,16 +1,10 @@
-- name: install mongodb
-  apt:
-    pkg:
-      - mongodb-org
-
-- name: enable replication sets
+- name: copy mongodb config
   notify:
   - restart mongodb
   - start mongodb replication
-  lineinfile:
-    path: /etc/mongod.conf
-    regexp: "^#replication:"
-    line: "replication:\n  replSetName: rs01"
+  template:
+    dest: /etc/mongod.conf
+    src: mongod.conf.j2
 
 - name: start and enable mongodb
   systemd:
diff --git a/templates/mongod.conf.j2 b/templates/mongod.conf.j2
new file mode 100644
index 0000000..64038b0
--- /dev/null
+++ b/templates/mongod.conf.j2
@@ -0,0 +1,44 @@
+# mongod.conf
+
+# 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:
diff --git a/vars/main.yml b/vars/main.yml
index 2256e1a..8b05881 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -1,4 +1,6 @@
 packages:
+  pkgs:
+    "mongodb-org": {}
   repos:
     mongodb:
       url: "deb http://repo.mongodb.org/apt/debian {{ ansible_distribution_release|lower }}/mongodb-org/{{ mongodb.version }} main"
-- 
GitLab