From 2b451cdda20bd3530fed1649c7d0a3ad4e1c6abb Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 24 Mar 2016 19:34:19 +0100 Subject: [PATCH] library/roles/mongodb-org-3: Better templating. Pass additional parameters with /etc/default/mongod. Removed the old configuration templates. --- mongodb-org-3/defaults/main.yml | 20 +++-- mongodb-org-3/handlers/main.yml | 8 +- mongodb-org-3/tasks/mongodb.yml | 9 ++- mongodb-org-3/templates/mongod-2.6.conf.j2 | 82 ------------------- mongodb-org-3/templates/mongod-3.0.conf.j2 | 26 +++--- mongodb-org-3/templates/mongod-default.j2 | 6 ++ mongodb-org-3/templates/mongodb-2.4.conf.j2 | 87 --------------------- 7 files changed, 45 insertions(+), 193 deletions(-) delete mode 100644 mongodb-org-3/templates/mongod-2.6.conf.j2 create mode 100644 mongodb-org-3/templates/mongod-default.j2 delete mode 100644 mongodb-org-3/templates/mongodb-2.4.conf.j2 diff --git a/mongodb-org-3/defaults/main.yml b/mongodb-org-3/defaults/main.yml index 6e0f1b36..2f0c35ae 100644 --- a/mongodb-org-3/defaults/main.yml +++ b/mongodb-org-3/defaults/main.yml @@ -3,23 +3,34 @@ mongodb_install_from_external_repo: True mongodb_install_packages: True mongodb_install_conf: True # Set to 'latest' if you want to get the latest available package -mongodb_pkg_state: installed +mongodb_pkg_state: latest mongodb_start_server: 'no' mongodb_tcp_port: 27017 -mongodb_http_interface: False +mongodb_http_interface: 'false' mongodb_http_port: 28017 mongodb_user: mongodb mongodb_group: mongodb mongodb_logdir: /var/log/mongodb -mongodb_log_file: mongodb.log +mongodb_log_file: mongod.log mongodb_logpath: '{{ mongodb_logdir }}/{{ mongodb_log_file }}' mongodb_dbpath: /var/lib/mongodb mongodb_log_retain_days: 7 -mongodb_directoryperdb: False +mongodb_directoryperdb: 'false' +mongodb_conf_file: /etc/mongod.conf +mongodb_daemon: /usr/bin/mongod +mongod_additional_options: "" mongodb_allowed_hosts: - 127.0.0.1/8 - '{{ ansible_default_ipv4.address }}/32' +mongodb_storage_engine: wiredTiger + +mongodb_systemlog_destination: file +mongodb_systemlog_logappend: 'true' +mongodb_systemlog_logrotate: reopen + + + mongodb_cluster_enabled: False mongodb_replicaset: storagedev mongodb_replica_keyfile: '{{ mongodb_dbpath }}/replica_keyfile' @@ -28,4 +39,3 @@ mongodb_ganglia_auth_enabled: False mongodb_ganglia_db: admin mongodb_ganglia_auth_mechanism: MONGODB-CR # User and password are stored in the variables mongo_monitoring_u and mongo_monitoring_pwd - diff --git a/mongodb-org-3/handlers/main.yml b/mongodb-org-3/handlers/main.yml index fbd0ae7f..f0772809 100644 --- a/mongodb-org-3/handlers/main.yml +++ b/mongodb-org-3/handlers/main.yml @@ -1,7 +1,5 @@ --- -- name: Update apt cache - apt: update_cache=yes - ignore_errors: true - -- name: Restart mongod +- name: Restart mongodb service: name=mongod state=restarted + when: "'{{ mongodb_start_server }}' == 'yes'" + diff --git a/mongodb-org-3/tasks/mongodb.yml b/mongodb-org-3/tasks/mongodb.yml index fb5f49eb..56785d3f 100644 --- a/mongodb-org-3/tasks/mongodb.yml +++ b/mongodb-org-3/tasks/mongodb.yml @@ -11,7 +11,7 @@ tags: mongodb - name: Install the mongodb repository - copy: content="deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" dest=/etc/apt/sources.list.d/mongodb-org-3.0.list owner=root group=root mode=044 + copy: content="deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/3.0 multiverse" dest=/etc/apt/sources.list.d/mongodb-org-3.0.list owner=root group=root mode=044 when: mongodb_install_from_external_repo register: external_repo tags: mongodb @@ -42,6 +42,13 @@ - name: Install the mongodb 3.0 configuration template: src=mongod-3.0.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0444 when: mongodb_install_conf + notify: Restart mongodb + tags: mongodb + +- name: Install the mongodb defaults file + template: src=mongod-default.j2 dest=/etc/default/mongod owner=root group=root mode=0444 + when: mongodb_install_conf + notify: Restart mongodb tags: mongodb - name: Install the cron job that manages log files rotation diff --git a/mongodb-org-3/templates/mongod-2.6.conf.j2 b/mongodb-org-3/templates/mongod-2.6.conf.j2 deleted file mode 100644 index 9e6d541d..00000000 --- a/mongodb-org-3/templates/mongod-2.6.conf.j2 +++ /dev/null @@ -1,82 +0,0 @@ -# mongod.conf - -# Where to store the data. - -# Note: if you run mongodb as a non-root user (recommended) you may -# need to create and set permissions for this directory manually, -# e.g., if the parent directory isn't mutable by the mongodb user. -dbpath={{ mongodb_dbpath }} -directoryperdb={{ mongodb_directoryperdb }} - -#where to log -logpath={{ mongodb_logpath }} - -logappend=true - -port = {{ mongodb_tcp_port }} - -# Listen to local interface only. Comment out to listen on all interfaces. -#bind_ip = 127.0.0.1 - -# Disables write-ahead journaling -# nojournal = true - -# Enables periodic logging of CPU utilization and I/O wait -#cpu = true - -# Turn on/off security. Off is currently the default -#noauth = true -#auth = true - -# Verbose logging output. -#verbose = true - -# Inspect all client data for validity on receipt (useful for -# developing drivers) -#objcheck = true - -# Enable db quota management -#quota = true - -# Set oplogging level where n is -# 0=off (default) -# 1=W -# 2=R -# 3=both -# 7=W+some reads -#diaglog = 0 - -# Ignore query hints -#nohints = true - - -{% if not mongodb_http_interface %} -# Disable the HTTP interface (Defaults to localhost:28017). -nohttpinterface = true -{% endif %} - -# Turns off server-side scripting. This will result in greatly limited -# functionality -#noscripting = true - -# Turns off table scans. Any query that would do a table scan fails. -#notablescan = true - -# Disable data file preallocation. -#noprealloc = true - -# Specify .ns file size for new databases. -# nssize = - -{% if mongodb_cluster_enabled %} -# Replication Options - -# in replicated mongo databases, specify the replica set name here -replSet = {{ mongodb_replicaset }} -# maximum size in megabytes for replication operation log -#oplogSize=1024 -# path to a key file storing authentication info for connections -# between replica set members -keyFile=/data/mongo_home/dev-d4science-keyfile -{% endif %} - diff --git a/mongodb-org-3/templates/mongod-3.0.conf.j2 b/mongodb-org-3/templates/mongod-3.0.conf.j2 index 1149b8eb..871adc92 100644 --- a/mongodb-org-3/templates/mongod-3.0.conf.j2 +++ b/mongodb-org-3/templates/mongod-3.0.conf.j2 @@ -8,37 +8,37 @@ storage: dbPath: {{ mongodb_dbpath }} journal: enabled: true - engine: wiredTiger + directoryPerDB: {{ mongodb_directoryperdb }} + engine: {{ mongodb_storage_engine }} # mmapv1: # wiredTiger: # where to write logging data. systemLog: - destination: file - logAppend: true + destination: {{ mongodb_systemlog_destination }} + logAppend: {{ mongodb_systemlog_logappend }} path: {{ mongodb_logpath }} + logRotate: {{ mongodb_systemlog_logrotate }} # network interfaces net: port: {{ mongodb_tcp_port }} -# bindIp: 127.0.0.1 - - + # bindIp: 127.0.0.1 + http: + enabled: {{ mongodb_http_interface }} + JSONPEnabled: {{ mongodb_http_interface }} + RESTInterfaceEnabled: {{ mongodb_http_interface }} + #processManagement: +{%if mongodb_cluster_enabled %} security: keyFile: /data/mongo_home/dev-d4science-keyfile -#operationProfiling: - replication: oplogSizeMB: 2000 replSetName: {{ mongodb_replicaset }} +{% endif %} #sharding: -## Enterprise-Only Options: - -#auditLog: - -#snmp: diff --git a/mongodb-org-3/templates/mongod-default.j2 b/mongodb-org-3/templates/mongod-default.j2 new file mode 100644 index 00000000..6fd002d8 --- /dev/null +++ b/mongodb-org-3/templates/mongod-default.j2 @@ -0,0 +1,6 @@ +ENABLE_MONGOD="{{ mongodb_start_server }}" +CONF={{ mongodb_conf_file }} +DAEMON={{ mongodb_daemon }} +DAEMONUSER={{ mongodb_user }} +DAEMON_OPTS="{{ mongod_additional_options }} --config $CONF" + diff --git a/mongodb-org-3/templates/mongodb-2.4.conf.j2 b/mongodb-org-3/templates/mongodb-2.4.conf.j2 deleted file mode 100644 index 47ea9f27..00000000 --- a/mongodb-org-3/templates/mongodb-2.4.conf.j2 +++ /dev/null @@ -1,87 +0,0 @@ -# Note: if you run mongodb as a non-root user (recommended) you may -# need to create and set permissions for this directory manually, -# e.g., if the parent directory isn't mutable by the mongodb user. -dbpath={{ mongodb_dbpath }} -directoryperdb={{ mongodb_directoryperdb }} - -#where to log -logpath={{ mongodb_logpath }} - -logappend=true - -port = {{ mongodb_tcp_port }} - -# Disables write-ahead journaling -# nojournal = true - -# Enables periodic logging of CPU utilization and I/O wait -#cpu = true - -# Turn on/off security. Off is currently the default -#noauth = true -#auth = true - -# Verbose logging output. -#verbose = true - -# Inspect all client data for validity on receipt (useful for -# developing drivers) -#objcheck = true - -# Enable db quota management -#quota = true - -# Set oplogging level where n is -# 0=off (default) -# 1=W -# 2=R -# 3=both -# 7=W+some reads -#diaglog = 0 -# Ignore query hints -#nohints = true - -{% if not mongodb_http_interface %} -# Disable the HTTP interface (Defaults to localhost:28017). -nohttpinterface = true -{% endif %} - -# Turns off server-side scripting. This will result in greatly limited -# functionality -#noscripting = true - -# Turns off table scans. Any query that would do a table scan fails. -#notablescan = true - -# Disable data file preallocation. -#noprealloc = true - -# Specify .ns file size for new databases. -# nssize = - -# Accout token for Mongo monitoring server. -#mms-token = - -# Server name for Mongo monitoring server. -#mms-name = - -# Ping interval for Mongo monitoring server. -#mms-interval = - -# Replication Options - -# in master/slave replicated mongo databases, specify here whether -# this is a slave or master -#slave = true -#source = master.example.com -# Slave only: specify a single database to replicate -#only = master.example.com -# or -#master = true -#source = slave.example.com - -{% if mongodb_cluster_enabled %} -# in replica set configuration, specify the name of the replica set -replSet = {{ mongodb_replicaset }} -{% endif %} -