From 356a1b5b6182192de3ee81ee3d87d38243e1efaa Mon Sep 17 00:00:00 2001 From: Kirill Klenov Date: Fri, 19 Dec 2014 17:39:09 +0300 Subject: [PATCH] Refactoring. Support MMS --- README.md | 59 ++++++++++++++++------------ defaults/main.yml | 53 +++++++++++++++---------- handlers/main.yml | 3 ++ meta/main.yml | 2 +- tasks/configure.yml | 6 +-- tasks/mms-agent.yml | 19 +++++++++ tasks/mongodb.yml | 3 ++ templates/automation-agent.config.j2 | 3 ++ templates/mongod.conf.j2 | 34 +++++++++------- 9 files changed, 118 insertions(+), 64 deletions(-) create mode 100644 tasks/mms-agent.yml create mode 100644 templates/automation-agent.config.j2 diff --git a/README.md b/README.md index 489d4c6..73ef147 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,9 @@ Stouts.mongo Ansible role which manage [MongoDB](http://www.mongodb.org/) -* Install and configure; +* Install and configure the MongoDB; * Provide hanlers for restart and reload; +* Setup MMS authomation agent; #### Variables @@ -15,32 +16,40 @@ Ansible role which manage [MongoDB](http://www.mongodb.org/) mongodb_enabled: yes mongodb_packages: - - python-selinux - - python-pymongo - - mongodb-org +- python-selinux +- python-pymongo +- mongodb-org -mongodb_conf: - auth: "false" - bind_ip: 127.0.0.1 - cpu: "true" - dbpath: /var/lib/mongodb/ - # diaglog: 0 # deprecated - logappend: "true" - logpath: /var/log/mongodb/mongod.log - noauth: "true" - nohints: "false" - nohttpinterface: "false" - nojournal: "true" - noprealloc: "false" - noscripting: "false" - notablescan: "false" - objcheck: "false" - port: 27017 - quota: "false" - # replSet: "" # Set for enable replication - verbose: "true" - vvvv: "true" +mongodb_user: mongodb +mongodb_conf_auth: no # Run with security +mongodb_conf_bind_ip: 127.0.0.1 # Comma separated list of ip addresses to listen on +mongodb_conf_cpu: yes # Periodically show cpu and iowait utilization +mongodb_conf_dbpath: /data/db # Directory for datafiles +mongodb_conf_fork: no # Fork server process +mongodb_conf_httpinterface: no # Enable http interface +mongodb_conf_ipv6: no # Enable IPv6 support (disabled by default) +mongodb_conf_journal: no # Enable journaling +mongodb_conf_logappend: yes # Append to logpath instead of over-writing +mongodb_conf_logpath: /var/log/mongodb/mongod.log # Log file to send write to instead of stdout +mongodb_conf_maxConns: 1000000 # Max number of simultaneous connections +mongodb_conf_noprealloc: no # Disable data file preallocation +mongodb_conf_noscripting: no # Disable scripting engine +mongodb_conf_notablescan: no # Do not allow table scans +mongodb_conf_port: 27017 # Specify port number +mongodb_conf_quota: no # Limits each database to a certain number of files +mongodb_conf_quotaFiles: 8 # Number of quota files +mongodb_conf_syslog: no # Log to system's syslog facility instead of file + +# Replica set options: +mongodb_conf_replSet: # Enable replication [/] +mongodb_conf_replIndexPrefetch: all # specify index prefetching behavior (if secondary) [none|_id_only|all] + +# MMS Agent +mongodb_mms_agent_pkg: https://mms.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_1.4.2.783-1_amd64.deb +mongodb_mms_group_id: "" +mongodb_mms_api_key: "" +mongodb_mms_base_url: https://mms.mongodb.com # Log rotation mongodb_logrotate: yes # Rotate mongodb logs. diff --git a/defaults/main.yml b/defaults/main.yml index f2b62f4..8f61930 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,29 +2,40 @@ mongodb_enabled: yes mongodb_packages: - - python-selinux - - python-pymongo - - mongodb-org +- python-selinux +- python-pymongo +- mongodb-org -mongodb_conf_auth: "false" -mongodb_conf_bind_ip: 127.0.0.1 -mongodb_conf_cpu: "true" -mongodb_conf_dbpath: /var/lib/mongodb/ -mongodb_conf_logappend: "true" -mongodb_conf_logpath: /var/log/mongodb/mongod.log -mongodb_conf_noauth: "true" -mongodb_conf_nohints: "false" -mongodb_conf_nohttpinterface: "false" -mongodb_conf_nojournal: "true" -mongodb_conf_noprealloc: "false" -mongodb_conf_noscripting: "false" -mongodb_conf_notablescan: "false" -mongodb_conf_objcheck: "false" -mongodb_conf_port: 27017 -mongodb_conf_quota: "false" -mongodb_conf_verbose: "true" -mongodb_conf_vvvv: "true" +mongodb_user: mongodb +mongodb_conf_auth: no # Run with security +mongodb_conf_bind_ip: 127.0.0.1 # Comma separated list of ip addresses to listen on +mongodb_conf_cpu: yes # Periodically show cpu and iowait utilization +mongodb_conf_dbpath: /data/db # Directory for datafiles +mongodb_conf_fork: no # Fork server process +mongodb_conf_httpinterface: no # Enable http interface +mongodb_conf_ipv6: no # Enable IPv6 support (disabled by default) +mongodb_conf_journal: no # Enable journaling +mongodb_conf_logappend: yes # Append to logpath instead of over-writing +mongodb_conf_logpath: /var/log/mongodb/mongod.log # Log file to send write to instead of stdout +mongodb_conf_maxConns: 1000000 # Max number of simultaneous connections +mongodb_conf_noprealloc: no # Disable data file preallocation +mongodb_conf_noscripting: no # Disable scripting engine +mongodb_conf_notablescan: no # Do not allow table scans +mongodb_conf_port: 27017 # Specify port number +mongodb_conf_quota: no # Limits each database to a certain number of files +mongodb_conf_quotaFiles: 8 # Number of quota files +mongodb_conf_syslog: no # Log to system's syslog facility instead of file + +# Replica set options: +mongodb_conf_replSet: # Enable replication [/] +mongodb_conf_replIndexPrefetch: all # specify index prefetching behavior (if secondary) [none|_id_only|all] + +# MMS Agent +mongodb_mms_agent_pkg: https://mms.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_1.4.2.783-1_amd64.deb +mongodb_mms_group_id: "" +mongodb_mms_api_key: "" +mongodb_mms_base_url: https://mms.mongodb.com # Log rotation mongodb_logrotate: yes # Rotate mongodb logs. diff --git a/handlers/main.yml b/handlers/main.yml index b6cfe60..753a8b8 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -5,3 +5,6 @@ - name: mongodb restart service: name=mongod state=restarted + +- name: mongodb-mms-automation-agent restart + service: name=mongodb-mms-automation-agent state=restarted diff --git a/meta/main.yml b/meta/main.yml index 787bdda..f617d63 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -5,7 +5,7 @@ dependencies: [] galaxy_info: author: klen company: Stouts - description: Manage mongodb + description: Manage MongoDB (MMS) license: MIT platforms: - name: Ubuntu diff --git a/tasks/configure.yml b/tasks/configure.yml index 2dd574a..72dbb6c 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -9,10 +9,10 @@ when: mongodb_logrotate - name: Create mongodb user - user: name=mongodb group=mongodb + user: name={{mongodb_user}} group={{mongodb_user}} - name: Configure database directory - file: state=directory path={{ mongodb_conf_dbpath }} owner=mongodb group=mongodb mode=0755 + file: state=directory path={{ mongodb_conf_dbpath }} owner={{mongodb_user}} group={{mongodb_user}} mode=0755 - name: Configure logs - file: state=file path={{ mongodb_conf_logpath }} owner=mongodb group=mongodb mode=0644 + file: state=file path={{ mongodb_conf_logpath }} owner={{mongodb_user}} group={{mongodb_user}} mode=0644 diff --git a/tasks/mms-agent.yml b/tasks/mms-agent.yml new file mode 100644 index 0000000..03c6b82 --- /dev/null +++ b/tasks/mms-agent.yml @@ -0,0 +1,19 @@ +--- + +- name: Install MMS agent pt. 1 + get_url: url={{mongodb_mms_agent_pkg}} dest={{mongodb_conf_dbpath}}/mms-agent.deb + register: mongodb_mms_agent_loaded + +- name: Install MMS agent pt. 2 + apt: deb={{mongodb_conf_dbpath}}/mms-agent.deb + when: mongodb_mms_agent_loaded.changed + +- name: Configure the MMS agent pt. 1 + file: state=directory path=/etc/mongodb-mms owner={{mongodb_user}} group={{mongodb_user}} mode=0755 + +- name: Configure the MMS agent pt. 2 + template: src=automation-agent.config.j2 dest=/etc/mongodb-mms/automation-agent.config + notify: mongodb-mms-automation-agent restart + +- name: Ensure that the MMS agent is started + service: name=mongodb-mms-automation-agent state=started enabled=yes diff --git a/tasks/mongodb.yml b/tasks/mongodb.yml index 61505c2..b31109a 100644 --- a/tasks/mongodb.yml +++ b/tasks/mongodb.yml @@ -8,3 +8,6 @@ - name: Ensure mongodb is started service: name=mongod state=started enabled=yes changed_when: False + +- include: mms-agent.yml + when: mongodb_mms_api_key != "" diff --git a/templates/automation-agent.config.j2 b/templates/automation-agent.config.j2 new file mode 100644 index 0000000..2a50d10 --- /dev/null +++ b/templates/automation-agent.config.j2 @@ -0,0 +1,3 @@ +mmsApiKey={{ mongodb_mms_api_key }} +mmsBaseUrl={{ mongodb_mms_base_url }} +mmsGroupId={{ mongodb_mms_group_id }} diff --git a/templates/mongod.conf.j2 b/templates/mongod.conf.j2 index b325792..e167561 100644 --- a/templates/mongod.conf.j2 +++ b/templates/mongod.conf.j2 @@ -1,20 +1,26 @@ # {{ ansible_managed }} -auth = {{ mongodb_conf_auth }} +auth = {{ mongodb_conf_auth|to_nice_json }} bind_ip = {{ mongodb_conf_bind_ip }} -cpu = {{ mongodb_conf_cpu }} +cpu = {{ mongodb_conf_cpu|to_nice_json }} dbpath = {{ mongodb_conf_dbpath }} -logappend = {{ mongodb_conf_logappend }} +fork = {{ mongodb_conf_fork|to_nice_json }} +httpinterface = {{ mongodb_conf_httpinterface|to_nice_json }} +ipv6 = {{ mongodb_conf_ipv6|to_nice_json }} +journal = {{ mongodb_conf_journal|to_nice_json }} +logappend = {{ mongodb_conf_logappend|to_nice_json }} logpath = {{ mongodb_conf_logpath }} -noauth = {{ mongodb_conf_noauth }} -nohints = {{ mongodb_conf_nohints }} -nohttpinterface = {{ mongodb_conf_nohttpinterface }} -nojournal = {{ mongodb_conf_nojournal }} -noprealloc = {{ mongodb_conf_noprealloc }} -noscripting = {{ mongodb_conf_noscripting }} -notablescan = {{ mongodb_conf_notablescan }} -objcheck = {{ mongodb_conf_objcheck }} +maxConns = {{ mongodb_conf_maxConns }} +noprealloc = {{ mongodb_conf_noprealloc|to_nice_json }} +noscripting = {{ mongodb_conf_noscripting|to_nice_json }} +notablescan = {{ mongodb_conf_notablescan|to_nice_json }} port = {{ mongodb_conf_port }} -quota = {{ mongodb_conf_quota }} -verbose = {{ mongodb_conf_verbose }} -vvvv = {{ mongodb_conf_vvvv }} +quota = {{ mongodb_conf_quota|to_nice_json }} +quotaFiles = {{ mongodb_conf_quotaFiles }} +syslog = {{ mongodb_conf_syslog|to_nice_json }} + +{% if mongodb_conf_replSet %} +# Replica set options: +replSet = {{ mongodb_conf_replSet }} +replIndexPrefetch = {{ mongodb_conf_replIndexPrefetch }} +{% endif %}