forked from ISTI-ansible-roles/ansible-roles
library/roles/mongodb: Add logrotate support. Permit the installation of specific mongodb versions from the mongodb repository.
d4science-ghn-cluster: Initial support to the automation of the mongo dev cluster.
This commit is contained in:
parent
6a092177ba
commit
bd10cfef79
|
@ -2,6 +2,8 @@
|
||||||
mongodb_install_from_external_repo: True
|
mongodb_install_from_external_repo: True
|
||||||
mongodb_install_packages: True
|
mongodb_install_packages: True
|
||||||
mongodb_install_conf: True
|
mongodb_install_conf: True
|
||||||
|
mongodb_latest_version: True
|
||||||
|
mongodb_specific_version: 2.4.3
|
||||||
mongodb_start_server: 'yes'
|
mongodb_start_server: 'yes'
|
||||||
mongodb_tcp_port: 27017
|
mongodb_tcp_port: 27017
|
||||||
mongodb_http_interface: False
|
mongodb_http_interface: False
|
||||||
|
@ -9,9 +11,14 @@ mongodb_http_port: 28017
|
||||||
mongodb_user: mongodb
|
mongodb_user: mongodb
|
||||||
mongodb_group: mongodb
|
mongodb_group: mongodb
|
||||||
mongodb_logdir: /var/log/mongodb
|
mongodb_logdir: /var/log/mongodb
|
||||||
mongodb_logpath: '{{ mongodb_logdir }}/mongodb.log'
|
mongodb_log_file: mongodb.log
|
||||||
|
mongodb_logpath: '{{ mongodb_logdir }}/{{ mongodb_log_file }}'
|
||||||
mongodb_dbpath: /var/lib/mongodb
|
mongodb_dbpath: /var/lib/mongodb
|
||||||
|
mongodb_log_retain_days: 7
|
||||||
mongodb_directoryperdb: False
|
mongodb_directoryperdb: False
|
||||||
mongodb_allowed_hosts:
|
mongodb_allowed_hosts:
|
||||||
- 127.0.0.1/8
|
- 127.0.0.1/8
|
||||||
- '{{ ansible_default_ipv4.address }}/32'
|
- '{{ ansible_default_ipv4.address }}/32'
|
||||||
|
|
||||||
|
mongodb_cluster_enabled: False
|
||||||
|
mongodb_replicaset: storagedev
|
||||||
|
|
|
@ -17,13 +17,24 @@
|
||||||
ignore_errors: True
|
ignore_errors: True
|
||||||
tags: mongodb
|
tags: mongodb
|
||||||
|
|
||||||
- name: Install the mongodb server
|
- name: Install the latest version of mongodb server
|
||||||
apt: pkg={{ item }} state=installed
|
apt: pkg={{ item }} state=latest
|
||||||
with_items:
|
with_items:
|
||||||
- mongodb-10gen
|
- mongodb-10gen
|
||||||
when:
|
when:
|
||||||
- mongodb_install_from_external_repo
|
- mongodb_install_from_external_repo
|
||||||
- mongodb_install_packages
|
- mongodb_install_packages
|
||||||
|
- mongodb_latest_version
|
||||||
|
tags: mongodb
|
||||||
|
|
||||||
|
- name: Install the mongodb server
|
||||||
|
apt: pkg={{ item }}={{ mongodb_specific_version }} state=present
|
||||||
|
with_items:
|
||||||
|
- mongodb-10gen
|
||||||
|
when:
|
||||||
|
- mongodb_install_from_external_repo
|
||||||
|
- mongodb_install_packages
|
||||||
|
- not mongodb_latest_version
|
||||||
tags: mongodb
|
tags: mongodb
|
||||||
|
|
||||||
- name: Install the mongodb server
|
- name: Install the mongodb server
|
||||||
|
@ -56,6 +67,10 @@
|
||||||
notify: Restart mongodb
|
notify: Restart mongodb
|
||||||
tags: 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
|
||||||
|
|
||||||
- name: Ensure mongodb is started
|
- name: Ensure mongodb is started
|
||||||
service: name=mongodb state=started enabled=yes
|
service: name=mongodb state=started enabled=yes
|
||||||
when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'yes' ) and ( mongodb_install_conf )
|
when: ( mongodb_start_server is defined ) and ( mongodb_start_server == 'yes' ) and ( mongodb_install_conf )
|
||||||
|
|
|
@ -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 {} \;
|
|
@ -80,5 +80,8 @@ nohttpinterface = true
|
||||||
#master = true
|
#master = true
|
||||||
#source = slave.example.com
|
#source = slave.example.com
|
||||||
|
|
||||||
|
{% if mongodb_cluster_enabled %}
|
||||||
# in replica set configuration, specify the name of the replica set
|
# in replica set configuration, specify the name of the replica set
|
||||||
# replSet = setname
|
replSet = {{ mongodb_replicaset }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue