From 1dfc4a8a795c49d925c9ddd0852fbf8248c484db Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Fri, 25 Mar 2016 18:04:45 +0100 Subject: [PATCH] dnet-openaire/mongodb.yml: Migrate to version 3.2 from 2.4. library/roles/mongodb-org-3.2: Support to upgrade from version 3.0. Fix the repo installation. library/roles/mongodb-org-3/tasks/mongodb.yml: Fix the repository installation. library/roles/mongodb-org/tasks/mongodb.yml: Fix the repository installation. library/roles/mongodb/tasks/main.yml: Fix the repository installation. --- mongodb-org-3.2/defaults/main.yml | 20 ++++- mongodb-org-3.2/handlers/main.yml | 8 +- mongodb-org-3.2/tasks/mongodb.yml | 52 +++++++++-- mongodb-org-3.2/templates/mongod-2.6.conf.j2 | 82 ----------------- ...{mongod-3.0.conf.j2 => mongod-3.2.conf.j2} | 26 +++--- mongodb-org-3.2/templates/mongod-default.j2 | 6 ++ mongodb-org-3.2/templates/mongodb-2.4.conf.j2 | 87 ------------------- mongodb-org-3/tasks/mongodb.yml | 4 +- mongodb-org/tasks/mongodb.yml | 4 +- mongodb/tasks/main.yml | 2 +- 10 files changed, 86 insertions(+), 205 deletions(-) delete mode 100644 mongodb-org-3.2/templates/mongod-2.6.conf.j2 rename mongodb-org-3.2/templates/{mongod-3.0.conf.j2 => mongod-3.2.conf.j2} (54%) create mode 100644 mongodb-org-3.2/templates/mongod-default.j2 delete mode 100644 mongodb-org-3.2/templates/mongodb-2.4.conf.j2 diff --git a/mongodb-org-3.2/defaults/main.yml b/mongodb-org-3.2/defaults/main.yml index f82d69fb..cc82a354 100644 --- a/mongodb-org-3.2/defaults/main.yml +++ b/mongodb-org-3.2/defaults/main.yml @@ -2,24 +2,36 @@ mongodb_install_from_external_repo: True mongodb_install_packages: True mongodb_install_conf: True +mongodb_upgrade_from_older_version: False # Set to 'latest' if you want to get the latest available package -mongodb_pkg_state: installed +mongodb_pkg_state: present 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' diff --git a/mongodb-org-3.2/handlers/main.yml b/mongodb-org-3.2/handlers/main.yml index fbd0ae7f..f0772809 100644 --- a/mongodb-org-3.2/handlers/main.yml +++ b/mongodb-org-3.2/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.2/tasks/mongodb.yml b/mongodb-org-3.2/tasks/mongodb.yml index 98903bd6..92ebbe92 100644 --- a/mongodb-org-3.2/tasks/mongodb.yml +++ b/mongodb-org-3.2/tasks/mongodb.yml @@ -1,11 +1,16 @@ --- - name: Check if Service mongod Exists - stat: path=/etc/init.d/mongod + 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 ) and ( mongodb_start_server is defined ) and ( mongodb_start_server == 'no' ) and ( mongodb_install_conf ) + when: + - service_mongod_status.stat.exists + - mongodb_start_server is defined + - mongodb_start_server == 'no' + - mongodb_install_conf tags: mongodb - name: Install the mongodb apt key @@ -14,14 +19,36 @@ when: mongodb_install_from_external_repo tags: mongodb -- name: Install the mongodb repository - copy: content="deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 multiverse" dest=/etc/apt/sources.list.d/mongodb-org-3.2.list owner=root group=root mode=044 - when: mongodb_install_from_external_repo - register: external_repo +- name: Remove the old mongo apt repositories + apt_repository: repo="{{ item }}" state=absent + with_items: + - "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" + when: + - mongodb_upgrade_from_older_version tags: mongodb -- name: Install the latest version of mongodb server - apt: pkg={{ item }} state={{ mongodb_pkg_state }} update_cache=yes +- name: Install the mongodb repository + apt_repository: repo="deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/3.2 multiverse" update_cache=yes state=present + when: mongodb_install_from_external_repo + tags: mongodb + +- name: We are upgrading, install the latest version of the mongo packages + apt: pkg={{ item }} state=latest + 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 + - mongodb_upgrade_from_older_version + tags: mongodb + +- name: Install the mongodb mongodb packages + apt: pkg={{ item }} state={{ mongodb_pkg_state }} with_items: - mongodb-org - mongodb-org-mongos @@ -46,13 +73,20 @@ - name: Install the mongodb 3.2 configuration template: src=mongod-3.2.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 tags: [ 'mongodb', 'mongo_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 ) tags: mongodb diff --git a/mongodb-org-3.2/templates/mongod-2.6.conf.j2 b/mongodb-org-3.2/templates/mongod-2.6.conf.j2 deleted file mode 100644 index 9e6d541d..00000000 --- a/mongodb-org-3.2/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.2/templates/mongod-3.0.conf.j2 b/mongodb-org-3.2/templates/mongod-3.2.conf.j2 similarity index 54% rename from mongodb-org-3.2/templates/mongod-3.0.conf.j2 rename to mongodb-org-3.2/templates/mongod-3.2.conf.j2 index 1149b8eb..871adc92 100644 --- a/mongodb-org-3.2/templates/mongod-3.0.conf.j2 +++ b/mongodb-org-3.2/templates/mongod-3.2.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.2/templates/mongod-default.j2 b/mongodb-org-3.2/templates/mongod-default.j2 new file mode 100644 index 00000000..6fd002d8 --- /dev/null +++ b/mongodb-org-3.2/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.2/templates/mongodb-2.4.conf.j2 b/mongodb-org-3.2/templates/mongodb-2.4.conf.j2 deleted file mode 100644 index 47ea9f27..00000000 --- a/mongodb-org-3.2/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 %} - diff --git a/mongodb-org-3/tasks/mongodb.yml b/mongodb-org-3/tasks/mongodb.yml index 56785d3f..713425cf 100644 --- a/mongodb-org-3/tasks/mongodb.yml +++ b/mongodb-org-3/tasks/mongodb.yml @@ -11,13 +11,13 @@ tags: mongodb - name: Install the mongodb repository - 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 + 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 }} update_cache=yes dpkg_options='force-confnew' + apt: pkg={{ item }} state={{ mongodb_pkg_state }} dpkg_options='force-confnew' with_items: - mongodb-org - mongodb-org-mongos diff --git a/mongodb-org/tasks/mongodb.yml b/mongodb-org/tasks/mongodb.yml index 2827b92a..4017ac1b 100644 --- a/mongodb-org/tasks/mongodb.yml +++ b/mongodb-org/tasks/mongodb.yml @@ -6,13 +6,13 @@ 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 + 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 - name: Install the latest version of mongodb server - apt: pkg={{ item }} state={{ mongodb_pkg_state }} update_cache=yes + apt: pkg={{ item }} state={{ mongodb_pkg_state }} with_items: - mongodb-org when: diff --git a/mongodb/tasks/main.yml b/mongodb/tasks/main.yml index 7083ecfc..d23a15d3 100644 --- a/mongodb/tasks/main.yml +++ b/mongodb/tasks/main.yml @@ -6,7 +6,7 @@ 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 + ansible_repository: repo="deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" update_cache=yes state=present when: mongodb_install_from_external_repo register: external_repo tags: mongodb