diff --git a/mongodb-org/defaults/main.yml b/mongodb-org/defaults/main.yml new file mode 100644 index 0000000..f259b68 --- /dev/null +++ b/mongodb-org/defaults/main.yml @@ -0,0 +1,23 @@ +--- +mongodb_install_from_external_repo: True +mongodb_install_packages: True +mongodb_install_conf: True +mongodb_latest_version: True +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: mongodb.log +mongodb_logpath: '{{ mongodb_logdir }}/{{ mongodb_log_file }}' +mongodb_dbpath: /var/lib/mongodb +mongodb_log_retain_days: 7 +mongodb_directoryperdb: False +mongodb_allowed_hosts: + - 127.0.0.1/8 + - '{{ ansible_default_ipv4.address }}/32' + +mongodb_cluster_enabled: False +mongodb_replicaset: storagedev diff --git a/mongodb-org/handlers/main.yml b/mongodb-org/handlers/main.yml new file mode 100644 index 0000000..b90f828 --- /dev/null +++ b/mongodb-org/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: Update apt cache + apt: update_cache=yes + ignore_errors: true + +- name: Restart mongodb + service: name=mongodb state=restarted diff --git a/mongodb-org/tasks/main.yml b/mongodb-org/tasks/main.yml new file mode 100644 index 0000000..fc9aab8 --- /dev/null +++ b/mongodb-org/tasks/main.yml @@ -0,0 +1,48 @@ +--- +- 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 + copy: content="deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" dest=/etc/apt/sources.list.d/mongodb.list owner=root group=root mode=044 + when: mongodb_install_from_external_repo + register: external_repo + tags: mongodb + +- name: Update the apt cache + apt: update_cache=yes + when: ( external_repo | changed ) + ignore_errors: True + tags: mongodb + +- name: Install the latest version of mongodb server + apt: pkg={{ item }} state=latest + with_items: + - mongodb-org + when: + - mongodb_install_from_external_repo + - mongodb_install_packages + - mongodb_latest_version + tags: mongodb + +- name: Install the mongodb defaults file + copy: content="ENABLE_MONGODB={{ mongodb_start_server }}" dest=/etc/default/mongodb owner=root group=root mode=0444 + when: mongodb_install_conf + 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 + +- name: Ensure mongodb is started + service: name=mongodb state=started enabled=yes + when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'yes' ) and ( mongodb_install_conf ) + tags: mongodb + +- name: Ensure mongodb is stopped and disabled + service: name=mongodb state=stopped enabled=no + when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'no' ) and ( mongodb_install_conf ) + tags: mongodb + diff --git a/mongodb-org/templates/mongo_log_rotate.sh.j2 b/mongodb-org/templates/mongo_log_rotate.sh.j2 new file mode 100644 index 0000000..7f5e494 --- /dev/null +++ b/mongodb-org/templates/mongo_log_rotate.sh.j2 @@ -0,0 +1,14 @@ +#!/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 {} \; diff --git a/mongodb-org/templates/mongodb-2.4.conf.j2 b/mongodb-org/templates/mongodb-2.4.conf.j2 new file mode 100644 index 0000000..47ea9f2 --- /dev/null +++ b/mongodb-org/templates/mongodb-2.4.conf.j2 @@ -0,0 +1,87 @@ +# 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 %} +