mongodb roles: Remove the obsolete ones. Now we have one role to install any mongodb 3.x version. See https://support.d4science.org/issues/12461

This commit is contained in:
Andrea Dell'Amico 2018-09-12 12:25:02 +02:00
parent f993dee88c
commit 11a5262fe3
29 changed files with 144 additions and 1771 deletions

View File

@ -1,75 +0,0 @@
---
mongodb_install_from_external_repo: True
mongodb_repo_keys:
- 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
- EA312927
- 0C49F3730359A14518585931BC711F9BA15703C6
mongodb_apt_repository: "deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/{{ mongodb_version }} multiverse"
mongodb_old_repositories:
- "deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/3.0 multiverse"
- "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"
mongodb_install_packages: True
mongodb_install_server: True
mongodb_install_conf: True
mongodb_upgrade_from_older_version: False
mongodb_version: 3.6
# Set to 'latest' if you want to get the latest available package
mongodb_pkg_state: present
mongodb_server_pkgs:
- mongodb-org
- mongodb-org-mongos
- mongodb-org-server
- mongodb-org-shell
- mongodb-org-tools
mongodb_client_pkgs:
- mongodb-org-shell
mongodb_start_server: 'yes'
mongodb_tcp_port: 27017
mongo_bind_ip: 0.0.0.0
mongodb_http_interface: 'false'
mongodb_http_port: 28017
mongodb_user: mongodb
mongodb_group: mongodb
mongodb_logdir: /var/log/mongodb
mongodb_log_file: mongod.log
mongodb_logpath: '{{ mongodb_logdir }}/{{ mongodb_log_file }}'
mongodb_dbpath: /var/lib/mongodb
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_ssl_enabled: False
mongodb_ssl_letsencrypt_managed: True
# Options: disabled, requireSSL, allowSSL, preferSSL
mongodb_ssl_mode: requireSSL
mongodb_ssl_certkey_file: /etc/pki/mongodb/mongodb.pem
mongodb_ssl_CA_file: /etc/ssl/certs/ca-certificates.crt
mongodb_ssl_allowConnectionsWithoutCertificates: 'true'
mongodb_ssl_disabled_protocols: 'TLS1_0,TLS1_1'
# Do not change the default. We do not manage a logrotate configuration yet
mongodb_systemlog_external_logrotate: False
mongodb_systemlog_destination: file
mongodb_log_retain_days: 7
# Not used anymore inside the template. Now we use different values based on mongodb_systemlog_external_logrotate
mongodb_systemlog_logappend: 'true'
mongodb_systemlog_logrotate: reopen
mongodb_cluster_enabled: False
mongodb_replicaset: storagedev
mongodb_replica_keyfile: '{{ mongodb_dbpath }}/replica_keyfile'
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

View File

@ -1,5 +0,0 @@
---
- name: Restart mongodb
service: name=mongod state=restarted
when: "'{{ mongodb_start_server }}' == 'yes'"

View File

@ -1,5 +0,0 @@
---
- import_tasks: mongodb.yml
- import_tasks: mongodb-letsencrypt-acmetool.yml
when: mongodb_ssl_letsencrypt_managed

View File

@ -1,92 +0,0 @@
---
- block:
- name: Check if Service mongod Exists
stat: path=/etc/init/mongod
register: service_mongod_status
tags: mongodb
- name: Ensure mongod is stopped and disabled
service: name=mongod state=stopped enabled=no
when:
- service_mongod_status.stat.exists
- mongodb_start_server is defined
- mongodb_start_server == 'no'
- mongodb_install_conf
when: mongodb_install_server
tags: mongodb
- block:
- name: Install the mongodb apt keys
apt_key: keyserver='hkp://keyserver.ubuntu.com:80' id={{ item }} state=present
with_items: '{{ mongodb_repo_keys }}'
when: mongodb_install_from_external_repo
register: apt_key_update_cache
- name: Update the apt cache after adding a new key
apt: update_cache=yes
when: apt_key_update_cache is changed
- name: Remove the old mongo apt repositories
apt_repository: repo='{{ item }}' state=absent update_cache=yes
with_items: '{{ mongodb_old_repositories }}'
when: mongodb_upgrade_from_older_version
- name: Install the mongodb repository
apt_repository: repo="{{ mongodb_apt_repository }}" update_cache=yes state=present
when: mongodb_install_from_external_repo
tags: [ 'mongodb', 'mongodb_client', 'mongodb_repo' ]
- block:
- name: Install the mongodb configuration
template: src=mongod-{{ mongodb_version }}.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0444 backup=yes
when: mongodb_install_conf
notify: Restart mongodb
- name: We are upgrading, install the latest version of the mongodb packages
apt: pkg={{ item }} state=latest update_cache=yes cache_valid_time=1800
with_items: '{{ mongodb_server_pkgs }}'
when:
- mongodb_install_from_external_repo
- mongodb_install_packages
- mongodb_upgrade_from_older_version
- name: Install the mongodb packages
apt: pkg={{ item }} state={{ mongodb_pkg_state }} update_cache=yes cache_valid_time=1800
with_items: '{{ mongodb_server_pkgs }}'
when:
- mongodb_install_from_external_repo
- mongodb_install_packages
- name: Create the mongodb log directory
file: dest={{ mongodb_logdir }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
- name: Create the mongodb db directory
file: dest={{ mongodb_dbpath }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
- 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
- name: Install the cron job that manages log files rotation
template: src=mongo_log_rotate.sh.j2 dest=/etc/cron.daily/mongo_log_rotate owner=root group=root mode=0555
when: not mongodb_systemlog_external_logrotate
- name: Ensure mongodb is started and enabled
service: name=mongod state=started enabled=yes
when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'yes' ) and ( mongodb_install_conf )
when: mongodb_install_server
tags: mongodb
- block:
- name: Install the mongodb client packages
apt: pkg={{ item }} state={{ mongodb_pkg_state }} update_cache=yes cache_valid_time=1800
with_items: '{{ mongodb_client_pkgs }}'
when: not mongodb_install_server
tags: [ 'mongodb', 'mongodb_client' ]

View File

@ -1,14 +0,0 @@
#!/bin/bash
MONGO_PID_FILE={{ mongodb_dbpath }}/mongod.lock
LOG_RETAIN_DAYS={{ mongodb_log_retain_days }}
RETVAL=
MONGO_PID=$( cat $MONGO_PID_FILE )
# Tell mongo to rotate its log file
kill -SIGUSR1 $MONGO_PID
RETVAL=$?
# Remove the old log files
find {{ mongodb_logdir }} -name "{{ mongodb_log_file }}.*" -ctime +$LOG_RETAIN_DAYS -exec rm -f {} \;

View File

@ -1,6 +0,0 @@
ENABLE_MONGOD="{{ mongodb_start_server }}"
CONF={{ mongodb_conf_file }}
DAEMON={{ mongodb_daemon }}
DAEMONUSER={{ mongodb_user }}
DAEMON_OPTS="{{ mongod_additional_options }} --config $CONF"

View File

@ -1,42 +0,0 @@
---
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: latest
mongodb_start_server: 'no'
mongodb_tcp_port: 27017
mongodb_http_interface: 'false'
mongodb_http_port: 28017
mongodb_user: mongodb
mongodb_group: mongodb
mongodb_logdir: /var/log/mongodb
mongodb_log_file: mongod.log
mongodb_logpath: '{{ mongodb_logdir }}/{{ mongodb_log_file }}'
mongodb_dbpath: /var/lib/mongodb
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
# Do not change the default. We do not manage a logrotate configuration yet
mongodb_systemlog_external_logrotate: False
mongodb_systemlog_destination: file
mongodb_log_retain_days: 7
# Not used anymore inside the template. Now we use different values based on mongodb_systemlog_external_logrotate
mongodb_systemlog_logappend: 'true'
mongodb_systemlog_logrotate: reopen
mongodb_cluster_enabled: False
mongodb_replicaset: storagedev
mongodb_replica_keyfile: '{{ mongodb_dbpath }}/replica_keyfile'
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

View File

@ -1,496 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# MongoDB gmond module for Ganglia
#
# Copyright (C) 2011 by Michael T. Conigliaro <mike [at] conigliaro [dot] org>.
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import json
import os
import re
import socket
import string
import time
import copy
NAME_PREFIX = 'mongodb_'
PARAMS = {
'server_status' : '~/mongodb-osx-x86_64-1.8.1/bin/mongo --host mongodb04.example.com --port 27018 --quiet --eval "printjson(db.serverStatus())"',
'rs_status' : '~/mongodb-osx-x86_64-1.8.1/bin/mongo --host mongodb04.example.com --port 27018 --quiet --eval "printjson(rs.status())"'
}
METRICS = {
'time' : 0,
'data' : {}
}
LAST_METRICS = copy.deepcopy(METRICS)
METRICS_CACHE_TTL = 3
def flatten(d, pre = '', sep = '_'):
"""Flatten a dict (i.e. dict['a']['b']['c'] => dict['a_b_c'])"""
new_d = {}
for k,v in d.items():
if type(v) == dict:
new_d.update(flatten(d[k], '%s%s%s' % (pre, k, sep)))
else:
new_d['%s%s' % (pre, k)] = v
return new_d
def get_metrics():
"""Return all metrics"""
global METRICS, LAST_METRICS
if (time.time() - METRICS['time']) > METRICS_CACHE_TTL:
metrics = {}
for status_type in PARAMS.keys():
# get raw metric data
io = os.popen(PARAMS[status_type])
# clean up
metrics_str = ''.join(io.readlines()).strip() # convert to string
metrics_str = re.sub('\w+\((.*)\)', r"\1", metrics_str) # remove functions
# convert to flattened dict
try:
if status_type == 'server_status':
metrics.update(flatten(json.loads(metrics_str)))
else:
metrics.update(flatten(json.loads(metrics_str), pre='%s_' % status_type))
except ValueError:
metrics = {}
# update cache
LAST_METRICS = copy.deepcopy(METRICS)
METRICS = {
'time': time.time(),
'data': metrics
}
return [METRICS, LAST_METRICS]
def get_value(name):
"""Return a value for the requested metric"""
# get metrics
metrics = get_metrics()[0]
# get value
name = name[len(NAME_PREFIX):] # remove prefix from name
try:
result = metrics['data'][name]
except StandardError:
result = 0
return result
def get_rate(name):
"""Return change over time for the requested metric"""
# get metrics
[curr_metrics, last_metrics] = get_metrics()
# get rate
name = name[len(NAME_PREFIX):] # remove prefix from name
try:
rate = float(curr_metrics['data'][name] - last_metrics['data'][name]) / \
float(curr_metrics['time'] - last_metrics['time'])
if rate < 0:
rate = float(0)
except StandardError:
rate = float(0)
return rate
def get_opcounter_rate(name):
"""Return change over time for an opcounter metric"""
master_rate = get_rate(name)
repl_rate = get_rate(name.replace('opcounters_', 'opcountersRepl_'))
return master_rate + repl_rate
def get_globalLock_ratio(name):
"""Return the global lock ratio"""
try:
result = get_rate(NAME_PREFIX + 'globalLock_lockTime') / \
get_rate(NAME_PREFIX + 'globalLock_totalTime') * 100
except ZeroDivisionError:
result = 0
return result
def get_indexCounters_btree_miss_ratio(name):
"""Return the btree miss ratio"""
try:
result = get_rate(NAME_PREFIX + 'indexCounters_btree_misses') / \
get_rate(NAME_PREFIX + 'indexCounters_btree_accesses') * 100
except ZeroDivisionError:
result = 0
return result
def get_connections_current_ratio(name):
"""Return the percentage of connections used"""
try:
result = float(get_value(NAME_PREFIX + 'connections_current')) / \
float(get_value(NAME_PREFIX + 'connections_available')) * 100
except ZeroDivisionError:
result = 0
return result
def get_slave_delay(name):
"""Return the replica set slave delay"""
# get metrics
metrics = get_metrics()[0]
# no point checking my optime if i'm not replicating
if 'rs_status_myState' not in metrics['data'] or metrics['data']['rs_status_myState'] != 2:
result = 0
# compare my optime with the master's
else:
master = {}
slave = {}
try:
for member in metrics['data']['rs_status_members']:
if member['state'] == 1:
master = member
if member['name'].split(':')[0] == socket.getfqdn():
slave = member
result = max(0, master['optime']['t'] - slave['optime']['t']) / 1000
except KeyError:
result = 0
return result
def get_asserts_total_rate(name):
"""Return the total number of asserts per second"""
return float(reduce(lambda memo,obj: memo + get_rate('%sasserts_%s' % (NAME_PREFIX, obj)),
['regular', 'warning', 'msg', 'user', 'rollovers'], 0))
def metric_init(lparams):
"""Initialize metric descriptors"""
global PARAMS
# set parameters
for key in lparams:
PARAMS[key] = lparams[key]
# define descriptors
time_max = 60
groups = 'mongodb'
descriptors = [
{
'name': NAME_PREFIX + 'opcounters_insert',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Inserts/Sec',
'slope': 'both',
'format': '%f',
'description': 'Inserts',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_query',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Queries/Sec',
'slope': 'both',
'format': '%f',
'description': 'Queries',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_update',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Updates/Sec',
'slope': 'both',
'format': '%f',
'description': 'Updates',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_delete',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Deletes/Sec',
'slope': 'both',
'format': '%f',
'description': 'Deletes',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_getmore',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Getmores/Sec',
'slope': 'both',
'format': '%f',
'description': 'Getmores',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_command',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Commands/Sec',
'slope': 'both',
'format': '%f',
'description': 'Commands',
'groups': groups
},
{
'name': NAME_PREFIX + 'backgroundFlushing_flushes',
'call_back': get_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Flushes/Sec',
'slope': 'both',
'format': '%f',
'description': 'Flushes',
'groups': groups
},
{
'name': NAME_PREFIX + 'mem_mapped',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'MB',
'slope': 'both',
'format': '%u',
'description': 'Memory-mapped Data',
'groups': groups
},
{
'name': NAME_PREFIX + 'mem_virtual',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'MB',
'slope': 'both',
'format': '%u',
'description': 'Process Virtual Size',
'groups': groups
},
{
'name': NAME_PREFIX + 'mem_resident',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'MB',
'slope': 'both',
'format': '%u',
'description': 'Process Resident Size',
'groups': groups
},
{
'name': NAME_PREFIX + 'extra_info_page_faults',
'call_back': get_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Faults/Sec',
'slope': 'both',
'format': '%f',
'description': 'Page Faults',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_ratio',
'call_back': get_globalLock_ratio,
'time_max': time_max,
'value_type': 'float',
'units': '%',
'slope': 'both',
'format': '%f',
'description': 'Global Write Lock Ratio',
'groups': groups
},
{
'name': NAME_PREFIX + 'indexCounters_btree_miss_ratio',
'call_back': get_indexCounters_btree_miss_ratio,
'time_max': time_max,
'value_type': 'float',
'units': '%',
'slope': 'both',
'format': '%f',
'description': 'BTree Page Miss Ratio',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_currentQueue_total',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Operations',
'slope': 'both',
'format': '%u',
'description': 'Total Operations Waiting for Lock',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_currentQueue_readers',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Operations',
'slope': 'both',
'format': '%u',
'description': 'Readers Waiting for Lock',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_currentQueue_writers',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Operations',
'slope': 'both',
'format': '%u',
'description': 'Writers Waiting for Lock',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_activeClients_total',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Clients',
'slope': 'both',
'format': '%u',
'description': 'Total Active Clients',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_activeClients_readers',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Clients',
'slope': 'both',
'format': '%u',
'description': 'Active Readers',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_activeClients_writers',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Clients',
'slope': 'both',
'format': '%u',
'description': 'Active Writers',
'groups': groups
},
{
'name': NAME_PREFIX + 'connections_current',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Connections',
'slope': 'both',
'format': '%u',
'description': 'Open Connections',
'groups': groups
},
{
'name': NAME_PREFIX + 'connections_current_ratio',
'call_back': get_connections_current_ratio,
'time_max': time_max,
'value_type': 'float',
'units': '%',
'slope': 'both',
'format': '%f',
'description': 'Percentage of Connections Used',
'groups': groups
},
{
'name': NAME_PREFIX + 'slave_delay',
'call_back': get_slave_delay,
'time_max': time_max,
'value_type': 'uint',
'units': 'Seconds',
'slope': 'both',
'format': '%u',
'description': 'Replica Set Slave Delay',
'groups': groups
},
{
'name': NAME_PREFIX + 'asserts_total',
'call_back': get_asserts_total_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Asserts/Sec',
'slope': 'both',
'format': '%f',
'description': 'Asserts',
'groups': groups
}
]
return descriptors
def metric_cleanup():
"""Cleanup"""
pass
# the following code is for debugging and testing
if __name__ == '__main__':
descriptors = metric_init(PARAMS)
while True:
for d in descriptors:
print (('%s = %s') % (d['name'], d['format'])) % (d['call_back'](d['name']))
print ''
time.sleep(METRICS_CACHE_TTL)

View File

@ -1,5 +0,0 @@
---
- name: Restart mongodb
service: name=mongod state=restarted
when: "'{{ mongodb_start_server }}' == 'yes'"

View File

@ -1,16 +0,0 @@
---
#
# The ganglia plugin comes from https://github.com/ganglia/gmond_python_modules
#
- name: Install the ganglia plugin for MongoDB
copy: src=mongodb.py dest=/usr/lib/ganglia/python_modules/mongodb.py owner=root group=root mode=0444
when: ganglia_enabled
notify: Restart ganglia monitor
tags: [ 'ganglia', 'mongodb' ]
- name: Distribute the ganglia (gmond) configuration for the MongoDB plugin
template: src=mongodb.pyconf.j2 dest=/etc/ganglia/conf.d/mongodb.pyconf owner=root group=root mode=0444
when: ganglia_enabled
notify: Restart ganglia monitor
tags: [ 'ganglia', 'mongodb' ]

View File

@ -1,4 +0,0 @@
---
- import_tasks: mongodb.yml
- import_tasks: ganglia-plugin.yml
when: ganglia_enabled

View File

@ -1,64 +0,0 @@
---
- name: Ensure mongod is stopped and disabled
service: name=mongod state=stopped enabled=no
when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'no' ) and ( mongodb_install_conf )
ignore_errors: True
tags: mongodb
- name: Install the mongodb apt key
#apt_key: id=7F0CEB10 state=present
raw: apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
when: mongodb_install_from_external_repo
tags: mongodb
- name: Install the mongodb repository
apt_repository: repo="deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/3.0 multiverse" state=present update_cache=yes
when: mongodb_install_from_external_repo
register: external_repo
tags: mongodb
- name: Install the latest version of mongodb server
apt: pkg={{ item }} state={{ mongodb_pkg_state }} dpkg_options='force-confnew'
with_items:
- mongodb-org
- mongodb-org-mongos
- mongodb-org-server
- mongodb-org-shell
- mongodb-org-tools
when:
- mongodb_install_from_external_repo
- mongodb_install_packages
tags: mongodb
- name: Create the mongodb log directory
file: dest={{ mongodb_logdir }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
tags: mongodb
- name: Create the mongodb db directory
file: dest={{ mongodb_dbpath }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
tags: mongodb
- 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
template: src=mongo_log_rotate.sh.j2 dest=/etc/cron.daily/mongo_log_rotate owner=root group=root mode=0555
when: not mongodb_systemlog_external_logrotate
tags: [ 'mongodb', 'mongo_logrotate' ]
- name: Ensure mongodb is started
service: name=mongod state=started enabled=yes
when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'yes' ) and ( mongodb_install_conf )
tags: mongodb

View File

@ -1,14 +0,0 @@
#!/bin/bash
MONGO_PID_FILE={{ mongodb_dbpath }}/mongod.lock
LOG_RETAIN_DAYS={{ mongodb_log_retain_days }}
RETVAL=
MONGO_PID=$( cat $MONGO_PID_FILE )
# Tell mongo to rotate its log file
kill -SIGUSR1 $MONGO_PID
RETVAL=$?
# Remove the old log files
find {{ mongodb_logdir }} -name "{{ mongodb_log_file }}.*" -ctime +$LOG_RETAIN_DAYS -exec rm -f {} \;

View File

@ -1,48 +0,0 @@
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: {{ mongodb_dbpath }}
journal:
enabled: true
directoryPerDB: {{ mongodb_directoryperdb }}
engine: {{ mongodb_storage_engine }}
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: {{ mongodb_systemlog_destination }}
path: {{ mongodb_logpath }}
{% if not mongodb_systemlog_external_logrotate %}
logRotate: rename
logAppend: false
{% else %}
logRotate: reopen
logAppend: true
{% endif %}
# network interfaces
net:
port: {{ mongodb_tcp_port }}
# 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
replication:
oplogSizeMB: 2000
replSetName: {{ mongodb_replicaset }}
{% endif %}
#sharding:

View File

@ -1,6 +0,0 @@
ENABLE_MONGOD="{{ mongodb_start_server }}"
CONF={{ mongodb_conf_file }}
DAEMON={{ mongodb_daemon }}
DAEMONUSER={{ mongodb_user }}
DAEMON_OPTS="{{ mongod_additional_options }} --config $CONF"

View File

@ -1,117 +0,0 @@
modules {
module {
name = "mongodb"
language = "python"
param server_status {
{% if mongodb_ganglia_auth_enabled %}
value = "mongo --quiet --authenticationMechanism {{ mongodb_ganglia_auth_mechanism }} -u {{ mongo_monitoring_u }} -p {{ mongo_monitoring_pwd }} --eval 'printjson(db.serverStatus())' {{ mongodb_ganglia_db }}"
{% else %}
value = "mongo --quiet --eval 'printjson(db.serverStatus())'"
{% endif %}
}
param rs_status {
{% if mongodb_ganglia_auth_enabled %}
value = "mongo --quiet --authenticationMechanism {{ mongodb_ganglia_auth_mechanism }} -u {{ mongo_monitoring_u }} -p {{ mongo_monitoring_pwd }} --eval 'printjson(rs.status())' {{ mongodb_ganglia_db }}"
{% else %}
value = "mongo --quiet --eval 'printjson(rs.status())'"
{% endif %}
}
}
}
collection_group {
collect_every = 30
time_threshold = 90
metric {
name = "mongodb_opcounters_insert"
title = "Inserts"
}
metric {
name = "mongodb_opcounters_query"
title = "Queries"
}
metric {
name = "mongodb_opcounters_update"
title = "Updates"
}
metric {
name = "mongodb_opcounters_delete"
title = "Deletes"
}
metric {
name = "mongodb_opcounters_getmore"
title = "Getmores"
}
metric {
name = "mongodb_opcounters_command"
title = "Commands"
}
metric {
name = "mongodb_backgroundFlushing_flushes"
title = "Flushes"
}
metric {
name = "mongodb_mem_mapped"
title = "Memory-mapped Data"
}
metric {
name = "mongodb_mem_virtual"
title = "Process Virtual Size"
}
metric {
name = "mongodb_mem_resident"
title = "Process Resident Size"
}
metric {
name = "mongodb_extra_info_page_faults"
title = "Page Faults"
}
metric {
name = "mongodb_globalLock_ratio"
title = "Global Write Lock Ratio"
}
metric {
name = "mongodb_indexCounters_btree_miss_ratio"
title = "BTree Page Miss Ratio"
}
metric {
name = "mongodb_globalLock_currentQueue_total"
title = "Total Operations Waiting for Lock"
}
metric {
name = "mongodb_globalLock_currentQueue_readers"
title = "Readers Waiting for Lock"
}
metric {
name = "mongodb_globalLock_currentQueue_writers"
title = "Writers Waiting for Lock"
}
metric {
name = "mongodb_globalLock_activeClients_total"
title = "Total Active Clients"
}
metric {
name = "mongodb_globalLock_activeClients_readers"
title = "Active Readers"
}
metric {
name = "mongodb_globalLock_activeClients_writers"
title = "Active Writers"
}
metric {
name = "mongodb_connections_current"
title = "Open Connections"
}
metric {
name = "mongodb_connections_current_ratio"
title = "Open Connections"
}
metric {
name = "mongodb_slave_delay"
title = "Replica Set Slave Delay"
}
metric {
name = "mongodb_asserts_total"
title = "Asserts per Second"
}
}

View File

@ -1,12 +1,36 @@
---
mongodb_install_from_external_repo: True
mongodb_repo_keys:
- 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
- EA312927
- 0C49F3730359A14518585931BC711F9BA15703C6
mongodb_apt_repository: "deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/{{ mongodb_version }} multiverse"
mongodb_old_repositories:
- "deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/3.0 multiverse"
- "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"
mongodb_install_packages: True
mongodb_install_server: True
mongodb_install_conf: True
mongodb_upgrade_from_older_version: False
mongodb_version: 3.6
# Set to 'latest' if you want to get the latest available package
mongodb_pkg_state: installed
mongodb_start_server: 'no'
mongodb_pkg_state: present
mongodb_server_pkgs:
- mongodb-org
- mongodb-org-mongos
- mongodb-org-server
- mongodb-org-shell
- mongodb-org-tools
mongodb_client_pkgs:
- mongodb-org-shell
mongodb_start_server: 'yes'
mongodb_tcp_port: 27017
mongodb_http_interface: False
mongo_bind_ip: 0.0.0.0
mongodb_http_interface: 'false'
mongodb_http_port: 28017
mongodb_user: mongodb
mongodb_group: mongodb
@ -14,16 +38,38 @@ mongodb_logdir: /var/log/mongodb
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
# --setParameter newCollectionsUsePowerOf2Sizes=false is useful if there are disk space constraints.
mongod_additional_options: ""
mongodb_allowed_hosts:
- 127.0.0.1/8
- '{{ ansible_default_ipv4.address }}/32'
mongodb_storage_engine: wiredTiger
mongodb_ssl_enabled: False
mongodb_ssl_letsencrypt_managed: True
# Options: disabled, requireSSL, allowSSL, preferSSL
mongodb_ssl_mode: requireSSL
mongodb_ssl_certkey_file: /etc/pki/mongodb/mongodb.pem
mongodb_ssl_CA_file: /etc/ssl/certs/ca-certificates.crt
mongodb_ssl_allowConnectionsWithoutCertificates: 'true'
mongodb_ssl_disabled_protocols: 'TLS1_0,TLS1_1'
# Do not change the default. We do not manage a logrotate configuration yet
mongodb_systemlog_external_logrotate: False
mongodb_systemlog_destination: file
mongodb_log_retain_days: 7
# Not used anymore inside the template. Now we use different values based on mongodb_systemlog_external_logrotate
mongodb_systemlog_logappend: 'true'
mongodb_systemlog_logrotate: reopen
mongodb_cluster_enabled: False
mongodb_replicaset: storagedev
mongodb_replica_keyfile: '{{ mongodb_dbpath }}/replica_keyfile'
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

View File

@ -1,496 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# MongoDB gmond module for Ganglia
#
# Copyright (C) 2011 by Michael T. Conigliaro <mike [at] conigliaro [dot] org>.
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import json
import os
import re
import socket
import string
import time
import copy
NAME_PREFIX = 'mongodb_'
PARAMS = {
'server_status' : '~/mongodb-osx-x86_64-1.8.1/bin/mongo --host mongodb04.example.com --port 27018 --quiet --eval "printjson(db.serverStatus())"',
'rs_status' : '~/mongodb-osx-x86_64-1.8.1/bin/mongo --host mongodb04.example.com --port 27018 --quiet --eval "printjson(rs.status())"'
}
METRICS = {
'time' : 0,
'data' : {}
}
LAST_METRICS = copy.deepcopy(METRICS)
METRICS_CACHE_TTL = 3
def flatten(d, pre = '', sep = '_'):
"""Flatten a dict (i.e. dict['a']['b']['c'] => dict['a_b_c'])"""
new_d = {}
for k,v in d.items():
if type(v) == dict:
new_d.update(flatten(d[k], '%s%s%s' % (pre, k, sep)))
else:
new_d['%s%s' % (pre, k)] = v
return new_d
def get_metrics():
"""Return all metrics"""
global METRICS, LAST_METRICS
if (time.time() - METRICS['time']) > METRICS_CACHE_TTL:
metrics = {}
for status_type in PARAMS.keys():
# get raw metric data
io = os.popen(PARAMS[status_type])
# clean up
metrics_str = ''.join(io.readlines()).strip() # convert to string
metrics_str = re.sub('\w+\((.*)\)', r"\1", metrics_str) # remove functions
# convert to flattened dict
try:
if status_type == 'server_status':
metrics.update(flatten(json.loads(metrics_str)))
else:
metrics.update(flatten(json.loads(metrics_str), pre='%s_' % status_type))
except ValueError:
metrics = {}
# update cache
LAST_METRICS = copy.deepcopy(METRICS)
METRICS = {
'time': time.time(),
'data': metrics
}
return [METRICS, LAST_METRICS]
def get_value(name):
"""Return a value for the requested metric"""
# get metrics
metrics = get_metrics()[0]
# get value
name = name[len(NAME_PREFIX):] # remove prefix from name
try:
result = metrics['data'][name]
except StandardError:
result = 0
return result
def get_rate(name):
"""Return change over time for the requested metric"""
# get metrics
[curr_metrics, last_metrics] = get_metrics()
# get rate
name = name[len(NAME_PREFIX):] # remove prefix from name
try:
rate = float(curr_metrics['data'][name] - last_metrics['data'][name]) / \
float(curr_metrics['time'] - last_metrics['time'])
if rate < 0:
rate = float(0)
except StandardError:
rate = float(0)
return rate
def get_opcounter_rate(name):
"""Return change over time for an opcounter metric"""
master_rate = get_rate(name)
repl_rate = get_rate(name.replace('opcounters_', 'opcountersRepl_'))
return master_rate + repl_rate
def get_globalLock_ratio(name):
"""Return the global lock ratio"""
try:
result = get_rate(NAME_PREFIX + 'globalLock_lockTime') / \
get_rate(NAME_PREFIX + 'globalLock_totalTime') * 100
except ZeroDivisionError:
result = 0
return result
def get_indexCounters_btree_miss_ratio(name):
"""Return the btree miss ratio"""
try:
result = get_rate(NAME_PREFIX + 'indexCounters_btree_misses') / \
get_rate(NAME_PREFIX + 'indexCounters_btree_accesses') * 100
except ZeroDivisionError:
result = 0
return result
def get_connections_current_ratio(name):
"""Return the percentage of connections used"""
try:
result = float(get_value(NAME_PREFIX + 'connections_current')) / \
float(get_value(NAME_PREFIX + 'connections_available')) * 100
except ZeroDivisionError:
result = 0
return result
def get_slave_delay(name):
"""Return the replica set slave delay"""
# get metrics
metrics = get_metrics()[0]
# no point checking my optime if i'm not replicating
if 'rs_status_myState' not in metrics['data'] or metrics['data']['rs_status_myState'] != 2:
result = 0
# compare my optime with the master's
else:
master = {}
slave = {}
try:
for member in metrics['data']['rs_status_members']:
if member['state'] == 1:
master = member
if member['name'].split(':')[0] == socket.getfqdn():
slave = member
result = max(0, master['optime']['t'] - slave['optime']['t']) / 1000
except KeyError:
result = 0
return result
def get_asserts_total_rate(name):
"""Return the total number of asserts per second"""
return float(reduce(lambda memo,obj: memo + get_rate('%sasserts_%s' % (NAME_PREFIX, obj)),
['regular', 'warning', 'msg', 'user', 'rollovers'], 0))
def metric_init(lparams):
"""Initialize metric descriptors"""
global PARAMS
# set parameters
for key in lparams:
PARAMS[key] = lparams[key]
# define descriptors
time_max = 60
groups = 'mongodb'
descriptors = [
{
'name': NAME_PREFIX + 'opcounters_insert',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Inserts/Sec',
'slope': 'both',
'format': '%f',
'description': 'Inserts',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_query',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Queries/Sec',
'slope': 'both',
'format': '%f',
'description': 'Queries',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_update',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Updates/Sec',
'slope': 'both',
'format': '%f',
'description': 'Updates',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_delete',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Deletes/Sec',
'slope': 'both',
'format': '%f',
'description': 'Deletes',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_getmore',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Getmores/Sec',
'slope': 'both',
'format': '%f',
'description': 'Getmores',
'groups': groups
},
{
'name': NAME_PREFIX + 'opcounters_command',
'call_back': get_opcounter_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Commands/Sec',
'slope': 'both',
'format': '%f',
'description': 'Commands',
'groups': groups
},
{
'name': NAME_PREFIX + 'backgroundFlushing_flushes',
'call_back': get_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Flushes/Sec',
'slope': 'both',
'format': '%f',
'description': 'Flushes',
'groups': groups
},
{
'name': NAME_PREFIX + 'mem_mapped',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'MB',
'slope': 'both',
'format': '%u',
'description': 'Memory-mapped Data',
'groups': groups
},
{
'name': NAME_PREFIX + 'mem_virtual',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'MB',
'slope': 'both',
'format': '%u',
'description': 'Process Virtual Size',
'groups': groups
},
{
'name': NAME_PREFIX + 'mem_resident',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'MB',
'slope': 'both',
'format': '%u',
'description': 'Process Resident Size',
'groups': groups
},
{
'name': NAME_PREFIX + 'extra_info_page_faults',
'call_back': get_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Faults/Sec',
'slope': 'both',
'format': '%f',
'description': 'Page Faults',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_ratio',
'call_back': get_globalLock_ratio,
'time_max': time_max,
'value_type': 'float',
'units': '%',
'slope': 'both',
'format': '%f',
'description': 'Global Write Lock Ratio',
'groups': groups
},
{
'name': NAME_PREFIX + 'indexCounters_btree_miss_ratio',
'call_back': get_indexCounters_btree_miss_ratio,
'time_max': time_max,
'value_type': 'float',
'units': '%',
'slope': 'both',
'format': '%f',
'description': 'BTree Page Miss Ratio',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_currentQueue_total',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Operations',
'slope': 'both',
'format': '%u',
'description': 'Total Operations Waiting for Lock',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_currentQueue_readers',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Operations',
'slope': 'both',
'format': '%u',
'description': 'Readers Waiting for Lock',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_currentQueue_writers',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Operations',
'slope': 'both',
'format': '%u',
'description': 'Writers Waiting for Lock',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_activeClients_total',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Clients',
'slope': 'both',
'format': '%u',
'description': 'Total Active Clients',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_activeClients_readers',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Clients',
'slope': 'both',
'format': '%u',
'description': 'Active Readers',
'groups': groups
},
{
'name': NAME_PREFIX + 'globalLock_activeClients_writers',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Clients',
'slope': 'both',
'format': '%u',
'description': 'Active Writers',
'groups': groups
},
{
'name': NAME_PREFIX + 'connections_current',
'call_back': get_value,
'time_max': time_max,
'value_type': 'uint',
'units': 'Connections',
'slope': 'both',
'format': '%u',
'description': 'Open Connections',
'groups': groups
},
{
'name': NAME_PREFIX + 'connections_current_ratio',
'call_back': get_connections_current_ratio,
'time_max': time_max,
'value_type': 'float',
'units': '%',
'slope': 'both',
'format': '%f',
'description': 'Percentage of Connections Used',
'groups': groups
},
{
'name': NAME_PREFIX + 'slave_delay',
'call_back': get_slave_delay,
'time_max': time_max,
'value_type': 'uint',
'units': 'Seconds',
'slope': 'both',
'format': '%u',
'description': 'Replica Set Slave Delay',
'groups': groups
},
{
'name': NAME_PREFIX + 'asserts_total',
'call_back': get_asserts_total_rate,
'time_max': time_max,
'value_type': 'float',
'units': 'Asserts/Sec',
'slope': 'both',
'format': '%f',
'description': 'Asserts',
'groups': groups
}
]
return descriptors
def metric_cleanup():
"""Cleanup"""
pass
# the following code is for debugging and testing
if __name__ == '__main__':
descriptors = metric_init(PARAMS)
while True:
for d in descriptors:
print (('%s = %s') % (d['name'], d['format'])) % (d['call_back'](d['name']))
print ''
time.sleep(METRICS_CACHE_TTL)

View File

@ -2,3 +2,4 @@
- name: Restart mongodb
service: name=mongod state=restarted
when: "'{{ mongodb_start_server }}' == 'yes'"

View File

@ -1,14 +0,0 @@
---
#
# The ganglia plugin comes from https://github.com/ganglia/gmond_python_modules
#
- name: Install the ganglia plugin for MongoDB
copy: src=mongodb.py dest=/usr/lib/ganglia/python_modules/mongodb.py owner=root group=root mode=0444
notify: Restart ganglia monitor
tags: [ 'ganglia', 'mongodb' ]
- name: Distribute the ganglia (gmond) configuration for the MongoDB plugin
template: src=mongodb.pyconf.j2 dest=/etc/ganglia/conf.d/mongodb.pyconf owner=root group=root mode=0444
notify: Restart ganglia monitor
tags: [ 'ganglia', 'mongodb' ]

View File

@ -1,4 +1,5 @@
---
- import_tasks: mongodb.yml
- import_tasks: ganglia-plugin.yml
when: ganglia_enabled
- import_tasks: mongodb-letsencrypt-acmetool.yml
when: mongodb_ssl_letsencrypt_managed

View File

@ -1,57 +1,92 @@
---
- name: Install the mongodb apt key
#apt_key: id=7F0CEB10 state=present
raw: apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
when: mongodb_install_from_external_repo
- block:
- name: Check if Service mongod Exists
stat: path=/etc/init/mongod
register: service_mongod_status
tags: mongodb
- name: Ensure mongod is stopped and disabled
service: name=mongod state=stopped enabled=no
when:
- service_mongod_status.stat.exists
- mongodb_start_server is defined
- mongodb_start_server == 'no'
- mongodb_install_conf
when: mongodb_install_server
tags: mongodb
- block:
- name: Install the mongodb apt keys
apt_key: keyserver='hkp://keyserver.ubuntu.com:80' id={{ item }} state=present
with_items: '{{ mongodb_repo_keys }}'
when: mongodb_install_from_external_repo
register: apt_key_update_cache
- name: Update the apt cache after adding a new key
apt: update_cache=yes
when: apt_key_update_cache is changed
- name: Remove the old mongo apt repositories
apt_repository: repo='{{ item }}' state=absent update_cache=yes
with_items: '{{ mongodb_old_repositories }}'
when: mongodb_upgrade_from_older_version
- name: Install the mongodb repository
ansible_repository: repo="deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" state=present update_cache=yes
when: mongodb_install_from_external_repo
register: external_repo
tags: mongodb
apt_repository: repo="{{ mongodb_apt_repository }}" update_cache=yes state=present
- name: Install the latest version of mongodb server
apt: pkg={{ item }} state={{ mongodb_pkg_state }}
with_items:
- mongodb-org
when: mongodb_install_from_external_repo
tags: [ 'mongodb', 'mongodb_client', 'mongodb_repo' ]
- block:
- name: Install the mongodb configuration
template: src=mongod-{{ mongodb_version }}.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0444 backup=yes
when: mongodb_install_conf
notify: Restart mongodb
- name: We are upgrading, install the latest version of the mongodb packages
apt: pkg={{ item }} state=latest update_cache=yes cache_valid_time=1800
with_items: '{{ mongodb_server_pkgs }}'
when:
- mongodb_install_from_external_repo
- mongodb_install_packages
tags: mongodb
- mongodb_upgrade_from_older_version
- name: Install the mongodb packages
apt: pkg={{ item }} state={{ mongodb_pkg_state }} update_cache=yes cache_valid_time=1800
with_items: '{{ mongodb_server_pkgs }}'
when:
- mongodb_install_from_external_repo
- mongodb_install_packages
- name: Create the mongodb log directory
file: dest={{ mongodb_logdir }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
- name: Create the mongodb db directory
file: dest={{ mongodb_dbpath }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
- 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: Create the mongodb db directory
file: dest={{ mongodb_dbpath }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
tags: mongodb
- name: Create the mongodb log directory
file: dest={{ mongodb_logdir }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
tags: mongodb
- name: Install the mongodb 2.6 configuration
template: src=mongod-2.6.conf.j2 dest=/etc/mongod.conf 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
template: src=mongo_log_rotate.sh.j2 dest=/etc/cron.daily/mongo_log_rotate owner=root group=root mode=0555
tags: [ 'mongodb', 'mongo_logrotate' ]
when: not mongodb_systemlog_external_logrotate
- name: Ensure mongodb is started
- name: Ensure mongodb is started and enabled
service: name=mongod state=started enabled=yes
when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'yes' ) and ( mongodb_install_conf )
when: mongodb_install_server
tags: mongodb
- name: Ensure mongod is stopped and disabled
service: name=mongod state=stopped enabled=no
when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'no' ) and ( mongodb_install_conf )
tags: mongodb
- block:
- name: Install the mongodb client packages
apt: pkg={{ item }} state={{ mongodb_pkg_state }} update_cache=yes cache_valid_time=1800
with_items: '{{ mongodb_client_pkgs }}'
when: not mongodb_install_server
tags: [ 'mongodb', 'mongodb_client' ]

View File

@ -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 = <size>
{% 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 %}

View File

@ -1,109 +0,0 @@
modules {
module {
name = "mongodb"
language = "python"
param server_status {
value = "mongo --quiet --eval 'printjson(db.serverStatus())'"
}
param rs_status {
value = "mongo --quiet --eval 'printjson(rs.status())'"
}
}
}
collection_group {
collect_every = 30
time_threshold = 90
metric {
name = "mongodb_opcounters_insert"
title = "Inserts"
}
metric {
name = "mongodb_opcounters_query"
title = "Queries"
}
metric {
name = "mongodb_opcounters_update"
title = "Updates"
}
metric {
name = "mongodb_opcounters_delete"
title = "Deletes"
}
metric {
name = "mongodb_opcounters_getmore"
title = "Getmores"
}
metric {
name = "mongodb_opcounters_command"
title = "Commands"
}
metric {
name = "mongodb_backgroundFlushing_flushes"
title = "Flushes"
}
metric {
name = "mongodb_mem_mapped"
title = "Memory-mapped Data"
}
metric {
name = "mongodb_mem_virtual"
title = "Process Virtual Size"
}
metric {
name = "mongodb_mem_resident"
title = "Process Resident Size"
}
metric {
name = "mongodb_extra_info_page_faults"
title = "Page Faults"
}
metric {
name = "mongodb_globalLock_ratio"
title = "Global Write Lock Ratio"
}
metric {
name = "mongodb_indexCounters_btree_miss_ratio"
title = "BTree Page Miss Ratio"
}
metric {
name = "mongodb_globalLock_currentQueue_total"
title = "Total Operations Waiting for Lock"
}
metric {
name = "mongodb_globalLock_currentQueue_readers"
title = "Readers Waiting for Lock"
}
metric {
name = "mongodb_globalLock_currentQueue_writers"
title = "Writers Waiting for Lock"
}
metric {
name = "mongodb_globalLock_activeClients_total"
title = "Total Active Clients"
}
metric {
name = "mongodb_globalLock_activeClients_readers"
title = "Active Readers"
}
metric {
name = "mongodb_globalLock_activeClients_writers"
title = "Active Writers"
}
metric {
name = "mongodb_connections_current"
title = "Open Connections"
}
metric {
name = "mongodb_connections_current_ratio"
title = "Open Connections"
}
metric {
name = "mongodb_slave_delay"
title = "Replica Set Slave Delay"
}
metric {
name = "mongodb_asserts_total"
title = "Asserts per Second"
}
}